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

Use @import JSDoc tags for TypeScript >= 5.5 #53

Merged
merged 1 commit into from
Sep 8, 2024

Conversation

blutorange
Copy link
Contributor

@blutorange blutorange commented Sep 5, 2024

These are easier to read than the /** @typedef */ workaround, and also take up less space. For each import, a separate @typedef is required.

TypeScript supports /** @import */ since version 5.5, see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#the-jsdoc-import-tag

I changed it so that it detects the current TypeScript version and uses @typedef for version < 5.5, and @import for versions >= 5.5. Perhaps you could also add an option for which import style to use, but I prefer less options, and @import seems like the proper way if supported. transpileFile has an optional tsVersion argument, which is needed for tests and could also be used by consumers if needed.

image

These are easier to read than the /** @typedef */ workaround, and also
take up less space. For each import, a separate @typedef is required.

TypeScript supports /** @import */ since version 5.5, see
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#the-jsdoc-import-tag

The script detects the current TypeScript version and uses @typedef for version < 5.5,
and @import for versions >= 5.5. Perhaps you could also add an option for which import
style to use, but I prefer less options. transpileFile has an optiona; `tsVersion` argument,
which is needed for tests and could also be used by consumers if needed.
@kungfooman
Copy link
Contributor

So nice!

and @import seems like the proper way if supported

Absolutely, the problem with @typedef is also that it's exporting the type by default... meaning that it creates a bunch of errors in these cases: microsoft/TypeScript#46011 (comment)

It was discussed back and forth without any consensus on how @typedef could/should be fixed, so simply adopting the new @import tag seems like a no-brainer. Nice work! 🥇

@futurGH
Copy link
Owner

futurGH commented Sep 8, 2024

Nice, did not realize this had been added! I like the tsVersion checking implementation as well. Much appreciated!

@futurGH futurGH merged commit 8fd0b83 into futurGH:main Sep 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants