-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: DecoratorsThe issue relates to the decorator syntaxThe issue relates to the decorator syntaxRevisitAn issue worth coming back toAn issue worth coming back toSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
Search Terms
export decorator class
Suggestion
Since TypeScript should be compatible with JavaScript, we should make decorator possible after the export.
Use Cases
Right now we have:
@Injectable()
export class CatsService {}
Should also be valid:
export @Injectable()
class CatsService {}
Examples
After searching around, it seem that @decorator
should come after the export
, even if I am still not completely sure, see how does Babel handle it:
import generate from '@babel/generator';
const { code } = generate({
type: 'ExportNamedDeclaration',
specifiers: [],
source: null,
declaration: {
type: 'ClassDeclaration',
decorators: [
{
type: 'Decorator',
expression: {
type: 'CallExpression',
callee: {
type: 'Identifier',
name: 'Injectable',
},
arguments: [],
},
},
],
id: {
type: 'Identifier',
name: 'CatsService',
},
superClass: null,
body: {
type: 'ClassBody',
body: [],
},
},
} as any);
console.log(code);
Will output:
export @Injectable()
class CatsService {}
Apparently this seem to be correct output adopted by TC39 proposal:
babel/babel#7526
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.
dd-pardal
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: DecoratorsThe issue relates to the decorator syntaxThe issue relates to the decorator syntaxRevisitAn issue worth coming back toAn issue worth coming back toSuggestionAn idea for TypeScriptAn idea for TypeScript