Parameters infer from body and call sites#28342
Conversation
If the function expression is the initialiser of a variable declaration.
| return InferFromReference.inferTypeFromReferences(getReferences(token, program, cancellationToken), program.getTypeChecker(), cancellationToken); | ||
| const references = getReferences(token, program, cancellationToken); | ||
| const checker = program.getTypeChecker(); | ||
| const types = InferFromReference.inferTypesFromReferences(references, checker, cancellationToken); |
There was a problem hiding this comment.
Seems like we could combine inferTypesFromReferences and unifyFromContext to avoid exposing two different functions?
There was a problem hiding this comment.
Well, the two are decoupled in inferTypeForParametersFromReferences; I decided to do the same here instead of keeping a function named inferTypeFromReferences around, which would just be the compose of inferTypesFromRefences >>> unifyFromContext.
If the pair were called together more than once I think a function like that would make sense. Right now it doesn't.
| let searchToken; | ||
| switch (containingFunction.kind) { | ||
| case SyntaxKind.Constructor: | ||
| searchToken = findChildOfKind<Token<SyntaxKind.ConstructorKeyword>>(containingFunction, SyntaxKind.ConstructorKeyword, sourceFile); |
There was a problem hiding this comment.
codeFixInferFromUsageMember3
There was a problem hiding this comment.
In other words, coverage is not great. I'm going to improve typing of JS constructor functions next, so I'll plan to add equivalent TS tests for each new JS test.
The latter change decreases coverage about 0.5% (the number of previously-any sites that are now annotated), but decreases the introduced error rate by more than 5%.