Omitted arguments are not candidates for possibly-undefined type parameters #61069
Labels
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Background
Playground Link
Consider the following code that is trying to leverage #56941.
This code has an optional parameter
canSelectMultiple
. Because it is optional, theMultiple
type parameters cannot simply be constrained toboolean
- they must factor inundefined
for various narrowing and assignability checks to work out.Most calls work as expected.
undefined
explicitly also worksHowever, if we omit the argument, we assume that there are no candidates for inference available and fall back to the constraint
boolean | undefined
. This changes our output type tostring | string[]
, which is an error in the following code:Proposal
When TypeScript infers type arguments to type parameters based on actual call arguments, we walk through parameters with missing corresponding arguments and infer from the type
undefined
to each parameter's type.Some things to consider if we discuss this:
The text was updated successfully, but these errors were encountered: