| ▲ | apatheticonion a day ago | ||||||||||||||||
Personally, given the limitations of JSDoc, I'd like to see a header-file like definition system for build-less applications (like libraries).
Where values in `index.js` can be typed in the header file with complete TypeScript syntax and those types are present in the target file via intellisense and type checking
And | |||||||||||||||||
| ▲ | MrJohz a day ago | parent [-] | ||||||||||||||||
This can be done, and is done in some projects, but the problem is that you need to manually maintain both sets of files, which can easily go out of sync if you're not careful. You also lose out on the ability to check your own code - using the header file you've written there, you can't really check the implementation of `useStr` to check that it works. The advantage of JSDoc is that the TypeScript compiler treats it as equivalent to TypeScript source code, which means you've still got access to type checking inside your functions. One thing I've seen in a few places is still to have DTS files that declare all sorts of types that are used in the application, and then have those files imported by JSDoc comments. That way, you've got TypeScript syntax for your types, which tend to get bulky and difficult to read in JSDoc syntax, but you still don't need a build system because the DTS imports are ignored completely at runtime. | |||||||||||||||||
| |||||||||||||||||