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

Consider annotated parameter with an initializer as optional when inferring from it #57708

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Mar 9, 2024

fixes #57706

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Mar 9, 2024
@@ -36542,7 +36542,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const declaration = signature.parameters[i].valueDeclaration as ParameterDeclaration;
const typeNode = getEffectiveTypeAnnotationNode(declaration);
if (typeNode) {
const source = addOptionality(getTypeFromTypeNode(typeNode), /*isProperty*/ false, isOptionalDeclaration(declaration));
const source = addOptionality(getTypeFromTypeNode(typeNode), /*isProperty*/ false, hasInitializer(declaration) || isOptionalDeclaration(declaration));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this matches the logic used by getTypeOfParameter

@sandersn sandersn added this to Not started in PR Backlog Mar 18, 2024
@typescript-bot typescript-bot removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Mar 20, 2024
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Mar 20, 2024
@sandersn sandersn moved this from Not started to Waiting on reviewers in PR Backlog Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
PR Backlog
  
Waiting on reviewers
Development

Successfully merging this pull request may close these issues.

Unexpected type infer for function first argument with default value since 5.1
3 participants