logoalt Hacker News

efortislast Sunday at 10:36 PM2 repliesview on HN

and types can be written in .d.ts file(s), which can be used in jsdoc out of the box (no import needed)


Replies

mirekrusinyesterday at 1:28 PM

that's not "jsdoc is typescript" anymore because you're falling back to something else - type definition files where you do have access wider typescript functionality.

also not a full solution - for .d.ts types to be available globally without explicit import the .d.ts file itself cannot use any imports/exports. this means you can't reuse types from other places to construct your types. you can workaround this by explicitly importing .d.ts in jsconfig/tsconfig but you're still left with other issues.

those types do actually become globally visible everywhere polluting global namespace which is bad in itself

there are no guarantees about them being in sync with actual code, which violates the whole point of using type safety.

they don't solve cases where you need typescript inlined functionality locally in your code or to perform assertion with satisfies operator etc.

g947olast Sunday at 11:19 PM

You could, but in a large codebase with multiple contributors, it easily becomes messy and confusing.