Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed contravariant inferences from annotated optional parameters #55397

Merged

Conversation

Andarist
Copy link
Contributor

fixes #55394

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Aug 16, 2023
@@ -35120,7 +35120,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (declaration.type) {
const typeNode = getEffectiveTypeAnnotationNode(declaration);
if (typeNode) {
inferTypes(inferenceContext.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
const source = addOptionality(getTypeFromTypeNode(typeNode), /*isProperty*/ false, hasQuestionToken(declaration));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasQuestionToken(declaration) isn't going to do the right thing for jsdoc optional parameters - instead, use the catch-all isOptionalDeclaration.

Copy link
Contributor Author

@Andarist Andarist Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 pushed out the appropriate change (and a test case)

@weswigham weswigham merged commit 3b49ce9 into microsoft:main Aug 16, 2023
19 checks passed
@Andarist Andarist deleted the fix/infer-from-annotated-optional-params branch August 16, 2023 21:51
snovader pushed a commit to mestro-se/TypeScript that referenced this pull request Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type inference changed for callbacks with optional parameters
3 participants