Skip to content

Fix inference for generic-typed constructor parameter when no explicit constructor is present - #47750

Merged
Wesley Wigham (weswigham) merged 2 commits into
microsoft:mainfrom
jihndai:issue/47340
Feb 15, 2022
Merged

Fix inference for generic-typed constructor parameter when no explicit constructor is present#47750
Wesley Wigham (weswigham) merged 2 commits into
microsoft:mainfrom
jihndai:issue/47340

Conversation

@jihndai

@jihndai jihndai (jihndai) commented Feb 6, 2022

Copy link
Copy Markdown
Contributor

When a class doesn't have an explicitly defined constructor, the class's default construct signature will have an undefined value in its declaration property. The issue then lies in the function getOrCreateTypeFromSignature: when the signature's declaration property is undefined, it would assume that it is a call signature instead of a construct signature.

For the fix, I think it would be safer to assume that the signature is a construct signature whenever declaration is undefined, as I couldn't find a scenario where a call signature would get passed to getOrCreateTypeFromSignature with an undefined value in declaration.

Fixes #47340

@ghost

Deleted user (ghost) commented Feb 6, 2022

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@typescript-bot TypeScript Bot (typescript-bot) added the For Backlog Bug PRs that fix a backlog bug label Feb 6, 2022
@weswigham

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) user test this inline

@typescript-bot

TypeScript Bot (typescript-bot) commented Feb 15, 2022

Copy link
Copy Markdown
Contributor

Heya Wesley Wigham (@weswigham), I've started to run the diff-based community code test suite on this PR at 0d5b019. You can monitor the build here.

Update: The results are in!

@typescript-bot

Copy link
Copy Markdown
Contributor

Wesley Wigham (@weswigham)
Great news! no new errors were found between main..refs/pull/47750/merge

@weswigham

Copy link
Copy Markdown
Member

Hm, happy to take this as the fix, I guess. I feel like somehow fixing the declaration to exist and point at the class could be a better change, but would be way way more involved; and since this doesn't seem to break anything, I guess this'll do.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Inference fails for generic-typed constructor parameter when no explicit constructor is present

5 participants