microsoft / microsoft/TypeScript
Signatures with less parameters aren't assignable to compatible targets with more when their rest param is an instantiated `NoInfer`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
NoInfer signature parameters list rest
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
declare function call<A extends readonly unknown[]>(
arg: (...args: NoInfer<A>) => void,
...args: A
): A;
// Argument of type '(a: number) => void' is not assignable to parameter of type '(...args: NoInfer<[number, number]>) => void'.
// Types of parameters 'a' and 'args' are incompatible.
// Type '[number, number]' is not assignable to type '[a: number]'.
// Source has 2 element(s) but target allows only 1.(2345)
const inferred = call((a: number) => {}, 1, 2);
// ^? function call<[number, number]>(arg: (...args: NoInfer<[number, number]>) => void, args_0: number, args_1: number): [number, number]
declare function call2<A extends readonly unknown[]>(
arg: (...args: A) => void,
...args: A
): A;
const inferred2 = call2<[number, number]>((a: number) => {}, 1, 2);
// ^? const inferred2: [number, number]
🙁 Actual behavior
The first call fails to typecheck
🙂 Expected behavior
Both of those calls use the same arguments. The first one is using NoInfer so the covariant inference can get prioritized. That prevents the instantiated signature from typechecking like the second one. Note that the first call infers the same type argument as the one that is supplied explicitly to the second call: [number, number]
Additional information about the issue
I think that this can be fixed by normalizing NoInfer<[A, B]> to [NoInfer<A>, NoInfer<B>]. This would be similar to what instantiateMappedTupleType does today at times.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground and reproduce the two calls using an instantiated NoInfer tuple. Trace the checker’s handling of NoInfer in tuple and rest-parameter assignability, especially the normalization behavior suggested in the issue. Done means the inferred call and explicitly typed call both type-check with the expected [number, number] tuple.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100