-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
[Experiment] feat(13626): Type annotations for default export #50536
Conversation
The TypeScript team hasn't accepted the linked issue #13626. If you can get it accepted, this PR will have a better chance of being reviewed. |
From reading the issue, it sounds like there are open questions, at least for how to parse the type. Can you explain what the problem is and how this PR solves it? (If there are too many questions it might be better to hold off on this PR and settle them on the original issue.) |
Using JsDoc, we can use the type annotation for the // @filename: /a.js
/** @type {string} */
export default 1;
^ Type 'number' is not assignable to type 'string'. However, in TypeScript, we cannot directly add type annotation for the export default: number ...
^ Expression expected
This is a PoC that allows using type annotation for the
Why did I use const a: number [] [] = [];
const b: {} [] = []; I think it would be weird to disallow using export default: number [] [] [];
^^^^^^^^^^^^^^^^
I think we need to find the best way to separate type annotation and expression.
export default<number> 1;
export default<number[]> []; @sandersn Do I need to add this answer to the issue and close PR? Maybe @RyanCavanaugh has thoughts about that case. |
I think so. The code changes are pretty small and the hard part is getting people to agree on the design, which is better done on an issue. Though, I don't know, maybe starting a new issue with your complete proposal would be easier to follow than appending it to the original. |
Fixes #13626