Repository navigation
Closed
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Suggestion
π Search Terms
jsdoc typedef export
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
Keep @typedef and @type local to file (or scope?) unless exported (at top-level of file).
π Motivating Example
I've come to find JSDoc + VS Code the best way to use TypeScript:
- There's no compile-phase
- Code is always valid as-is
- Forgetting to build isn't fatal
- Often vastly simplifies tool chain
- You just use it within VS Code
- Let it show in-IDE errors
- Let it install/run TypeScript for you
- Still provides autocompletion and everything
- Encourages avoiding insanely complex types
- You can still make complex types via index.d.ts if really necessary
- You usually already want to document function parameters anyway, might as well use JSDoc
- Function declaration lines don't end up being 500 characters, since you can put each parameter on each line
It's overall a pretty good alternative to TypeScript in small/medium projects.
But it has this one big caveat: All types/typedefs in any files are visible in all files.
- This means you can't cleanly have helper types encapsulated to a file.
- And you can't mark types as being exportable, which means you can't have multiple types with the same name.
Fixing this would make JSDoc an extremely useful way to use TypeScript with the "almost zero config" VS Code approach.
(There's also #42949 which is unrelated to this except that it's one small but fixable thing making JSDoc support not as useful as TypeScript syntax.)
π» Use Cases
^
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Activity
sdegutis commentedon Mar 15, 2021
Never mind, looks like this is already how it behaves. Not sure why I thought otherwise.
kungfooman commentedon May 9, 2023
They will definitely be exported as you can see from this error: #46011 (comment)
Anyone happens to know which PR changed this behaviour then? That would be a starting point to fix the behaviour, personally I would like a possible
@privatefield on@typedef's.ljharb commentedon Oct 5, 2023
I'm running into this now; I have a CJS file with JSDoc comments that's generating types, and the resulting types have
export =(as they should) for the CJS value, and alsoexport typefor the typedef, despite not explicitly exporting it.This should be reopened.