Hey @trusktr ! Thank you for your answer and advice!
I knew about auto-import when the type is declared via JSDoc comments and also about the new @import feature (I followed and contributed to the discussion on this feature here). However, I prefer the type declaration using let + JSDoc comments, as shown in the screenshots above. The main issue with using comments is that there are no ESLint rules to lint them. It's easy to forget to delete something because rules like "no-unused-vars" or "sorted-imports" don't work for type declarations and imports in JSDoc comments.
The issue about annotations as comments is really good! I wasn't aware of it. I've subscribed to it and will follow all the discussions. Thank you!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You can export a type without making a variable:
This automatically exports the type.
With TS pre 5.5, you can import it like this in another file:
With TS 5.5 and above, you can import with JSDoc
@import
syntax:Basically just wrap an import statement with
/**@
and*/
to convert it to type-only import comment.If you want to avoid
@private
, you can use official JS private syntax:Also check out some proposals for simplified and more concise type comment syntax here:
github.com/microsoft/TypeScript/is...
For example see how concise this is compared to JSDoc:
Hey @trusktr ! Thank you for your answer and advice!
I knew about auto-import when the type is declared via JSDoc comments and also about the new
@import
feature (I followed and contributed to the discussion on this feature here). However, I prefer the type declaration usinglet
+ JSDoc comments, as shown in the screenshots above. The main issue with using comments is that there are no ESLint rules to lint them. It's easy to forget to delete something because rules like "no-unused-vars" or "sorted-imports" don't work for type declarations and imports in JSDoc comments.The issue about annotations as comments is really good! I wasn't aware of it. I've subscribed to it and will follow all the discussions. Thank you!