-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Search Terms
const jsdoc
Suggestion
v3.4 added support for as const
to mark a literal expression as immutable and disable type widening. This feature uses the TypeScript type assertion syntax {} as const
or <const>{}
.
In JS files you can use JSDoc to do type assertions: /** @type {T} */(v)
Unfortunately that doesn't work with const assertions.
// @ts-check
const foo = /** @type {const} */([1]); // Error: cannot find name 'const'
This proposes adding support for /** @type {const} */([1])
.
An alternative could be /** @const */([1])
.
Use Cases
The same as for const assertions in TS files.
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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
yln99517, Aliaksei-Martsinkevich, ExE-Boss, kohlmannj, DullReferenceException and 92 more
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript