Skip to content

fix(47946): Literal types cannot be used in JSDoc export default { } syntax #47951

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

Merged
merged 1 commit into from
Mar 1, 2022

Conversation

a-tarasyuk
Copy link
Contributor

@a-tarasyuk a-tarasyuk commented Feb 18, 2022

Fixes #47946

@typescript-bot typescript-bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Feb 18, 2022
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

I'll leave a comment on the issue laying out some design questions, but for now I'm assuming that the semantics of /** @type {T} */ export default { ... } are like

export const default: T = { ... }

I suspect that contextual typing isn't going to work here, and that getTypeofVariableOrParameterOrProperty is the only way to do this right.

@sandersn sandersn self-assigned this Feb 28, 2022
@sandersn sandersn requested a review from gabritto February 28, 2022 18:38
@a-tarasyuk
Copy link
Contributor Author

checkObjectLiteral uses checkExpressionForMutableLocation/checkPropertyAssignment which depends on getContextualType (isLiteralOfContextualType(type, contextualType))) to set prop.type. Do we need to continue to use widened type for props in this case?

@sandersn
Copy link
Member

sandersn commented Mar 1, 2022

I had forgotten about your work in #45342. Now that I re-read that, I see that you already wrote the code in getTypeOfVariableOrParameterOrProperty. Thanks for your follow-up explanation pointing out the source of the bug. It cleared up my confusion.

@sandersn sandersn merged commit 0637148 into microsoft:main Mar 1, 2022
@nicojs
Copy link

nicojs commented Mar 2, 2022

Thanks a lot for fixing!

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
Archived in project
Development

Successfully merging this pull request may close these issues.

Literal types cannot be used in JSDoc export default { } syntax
4 participants