I have code to prepend element to array. It works great on playground check the playground link But when i run same code locally it works another.
export type ArrayWrap<T> = T extends any[] ? T : [T];
export type PrependArray<A, B extends Array<any>> = B extends any[]
? ((a: A, ...b: B) => any) extends (...args: infer U) => any
? U
: never
: ArrayWrap<A>;
type T = PrependArray<"a", ["b"]>; // expected ["a", "b"] but makes ["a", ..."b"[]]
Not sure if it could be related to config of TS
Edit 2: So i found that in one package of project it is as expected in second (Storybook package) it seems it is wrong.
Working package TS config:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": false,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"experimentalDecorators": true,
"strictNullChecks": false
},
"include": ["src"]
}
Not working package TS config:
{
"compilerOptions": {
"outDir": "build/lib",
"module": "commonjs",
"target": "es5",
"lib": ["es5", "es6", "es7", "es2017", "dom"],
"sourceMap": true,
"allowJs": false,
"jsx": "react",
"moduleResolution": "node",
"rootDirs": ["stories", "test"],
"baseUrl": ".",
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"isolatedModules": true,
"noEmit": false
},
"include": ["stories/**/*", "test/**/*"],
"exclude": ["node_modules", "build", "scripts"]
}