Open
Description
π Search Terms
function signature wrong pick
π Version & Regression Information
- Tested with the nightly build.
β― Playground Link
π» Code
type Extension = {
args: Record<string, any>
};
// black magic from https://www.geeksforgeeks.org/union-type-to-intersection-type-in-typescript/
type UnionToIntersection<U> = (
U extends any ? (k: U) => void : never
) extends (k: infer I) => void
? I
: never;
type Args<T extends Extension[]> = UnionToIntersection<T[keyof T & number]["args"]>
export function LISS(args: NoInfer<Args<[{args: {css: string[]}}]>>)
: true
export function LISS<T extends Extension[]>( args: NoInfer<Args<T>>,
...extensions: T): false
export function LISS<T extends Extension[]>(args: NoInfer<Args<T>>,
...extensions: T): boolean {
return {} as boolean
}
const a = LISS({ css: [] as any[]}); // should be true
const b = LISS({ css: [] as string[]}); // ok
π Actual behavior
typeof a
is false
when it should be true
: i.e. the second signature overload is chosen.
π Expected behavior
typeof a
should be true
: i.e. the first signature overload should be chosen.
Additional information about the issue
Using T extends [Extension, ...Extension[]]
fixes the issue in the example (force the second signature to have at least one extension). But the underlying issue might manifest in other cases.
Note: It would be simpler to write :
const exts = [{args: {css: string[]}}];
export function LISS<T extends Extension[] = typeof exts>(
args: NoInfer<Args<T>>,
...extensions: T = exts): ...`
But TS doesn't allow us to do so, hence the function signature overload.
Metadata
Metadata
Assignees
Labels
No labels