4 ms·
You can also use jsdoc to ask tools like vs code to run js as typescript and complement your variables with typing information. I used this recently for a proj
by maushu 5y ago
You can also use jsdoc to ask tools like vs code to run js as typescript and complement your variables with typing information.
I used this recently for a project that couldn't use typescript.
- darekkay 5y agoThat's also useful in mixed JS/TS project (e.g. during a migration). I wrote a short guide: https://darekkay.com/blog/javascript-type-comments/ https://darekkay.com/blog/javascript-type-comments/
- mirekrusin 5y agoShame typescript doesn't support flow-like mode where types can sit in comments – making whole file valid js. Not everything can be expressed with jsdoc types.
- machiaweliczny 5y agoYou still can have .d.ts file and refer to that in JSDOC
- mirekrusin 5y agoAnnotations on exported part only is not the whole picture of typescript.
- cprecioso 5y agoYou can have full TypeScript types in JSDoc-type comments: https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html https://www.typescriptlang.org/docs/handbook/jsdoc-supported...
- mirekrusin 5y agoNot really, I want to inline /*: ... */ type annotations with terse ts code _and_ use /*:: ... */ to escape into normal typescript language where I can define arbitrary number of intermediate types and just use typescript as normal typescript, not some stripped down nonsense at limited positions.
- IshKebab 5y agoIt's better than nothing but not really a good substitute for actual Typescript.