Skip to content

Fixed contravariant inferences from annotated optional parameters - #55397

Merged
Wesley Wigham (weswigham) merged 2 commits into
microsoft:mainfrom
Andarist:fix/infer-from-annotated-optional-params
Aug 16, 2023
Merged

Fixed contravariant inferences from annotated optional parameters#55397
Wesley Wigham (weswigham) merged 2 commits into
microsoft:mainfrom
Andarist:fix/infer-from-annotated-optional-params

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

fixes#55394

Comment threadsrc/compiler/checker.ts Outdated
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
Copy Markdown
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.

@AndaristMateusz Burzyński (Andarist)Aug 16, 2023

Copy link
Copy Markdown
ContributorAuthor

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
Wesley Wigham (weswigham) merged commit 3b49ce9 into microsoft:mainAug 16, 2023
@Andarist
Mateusz Burzyński (Andarist) deleted the fix/infer-from-annotated-optional-params branch August 16, 2023 21:51
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Milestone BugPRs 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

@Andarist@weswigham@typescript-bot