-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Now that decorators are supported in TypeScript (#2249), consider adding support for ambient/design-time-only decorators:
Ambient decorators can be an extensible way to declare properties on or associate special behavior to declarations; design time tools can leverage these associations to produce errors or produce documentation. For example:
Use cases:
- Deprecated/Obsolete, to support warning on use of specific API’s:
interface JQuery {
/**
* A selector representing selector passed to jQuery(), if any, when creating the original set.
* version deprecated: 1.7, removed: 1.9
*/
@@deprecated("Property is only maintained to the extent needed for supporting .live() in the jQuery Migrate plugin. It may be removed without notice in a future version.", false)
selector: string;
}- Suppress linter warning:
@@suppressWarning("disallow-leading-underscore")
function __init() {
}Proposal
Design-time (Ambient) decorators are:
- ambient functions
- have a special name starting with "@"
- are not emitted in output JS code, but persisted in .d.ts outputs.
Application
- Applying a design-time can only accept constant values. Variables would not be observable by the compiler at compile time. Here is the set of possible values:
- string literal,
- number literal,
- regexp literal,
- true keyword,
- false keyword,
- null keyword,
- undefined symbol,
- const enum members,
- array literals of one of the previous kinds,
- object literal with only properties with values of one of the previous kinds
niieani, remojansen, tobich, mquandalle, garkin and 127 morefelixfbecker and Dean177asyncliz, OctoD, happybang, l0ll098, victorhtc and 9 more
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript