Set inference result to any instead of {} for .js files if generic type parameter inference found no candidates#14492
Conversation
…c type parameter inference found no candidates
| context.inferredTypes[index] = inferredType = instantiatedConstraint; | ||
| } | ||
| } | ||
| if (context.useAnyForNoInferences && !inferences.length && inferredType === emptyObjectType) { |
There was a problem hiding this comment.
Why this logic when we're already doing similar checks above? I would just modify the inferredType = emptyObjectType assignment above to inferredType = context.usAnyForNoInferences ? anyType : emptyObjectType.
There was a problem hiding this comment.
This means you never get the constraint if one exist, always get any, since any will always be assignable to any constraint. For foo<T extends number>(): T number seemed like a better result than any.
There was a problem hiding this comment.
Ah, I thought the new code was in a different place but I see now. Anyway, one issue is that you'll change any emptyObjectType into an any regardless of how that emptyObjectType came about. It might in fact have been produced by an actual inference.
There was a problem hiding this comment.
should be updated now.
//CC @ahejlsberg