Repository navigation
Decorators #2249
Description
Activity
- addedSpecIssues related to the TypeScript language specificationIssues related to the TypeScript language specification
on Mar 7, 2015 fdecampredon commented
on Mar 7, 2015 More actionsExcuse me from what I understand of the spec, we won't be able to do:
@F function test() { }Am I right ?
Reacted by Adam PietrasiakHow does type serialization work with rest arguments?
@F() class Foo { constructor(...args: string[]) { } } function F(@paramterTypes types?: Function[]) { return function (target) { target.paramterTypes = types; // ??? } }
Using decorators seems straightforward enough, but I found the sections about declaring them to be confusing. C.4 says decorators need to be annotated with
@decorator, but not a single one of the examples actually shows this happening.Are decorator factories intended to be classes that implement the interfaces found in B?
JsonFreeman commented
on Mar 7, 2015 ContributorMore actionsWhat is the rule for refining the interpretation of CoverMemberExpressionSquareBracketsAndComputedPropertyName?
JsonFreeman commented
on Mar 7, 2015 ContributorMore actionsI noticed many of the typings have
Function | Objectat various points, but these will degenerate to Object at type check time. What is the reason to have Function there?JsonFreeman commented
on Mar 7, 2015 ContributorMore actionsI am not crazy about the terms DecoratorFunction vs DecoratorFactory. I'd much rather follow the nomenclature of generators, which has Generator and GeneratorFunction. With this scheme, we would rename DecoratorFunction to Decorator, and DecoratorFactory to DecoratorFunction.
JsonFreeman commented
on Mar 7, 2015 ContributorMore actionsFor the decorated exports, what is
[lookahead ≠ @]for? Can HoistableDeclaration and ClassDeclaration actually start with a@?This is a dup of #1557
JsonFreeman commented
on Mar 8, 2015 ContributorMore actionsIt's not really a dupe, as #1557 was for a different design. This issue is for the decorators design being implemented now.
My mistake.
fdecampredon commented
on Mar 9, 2015 More actionsFor decorator on function expression, could we not do something like :
@F("color") @G function myFunc() { doSomething(); }
transformed in :
var _t = function() { doSomething(); } _t = F("color")(_t = G(_t) || _t) || _t; function myFunc() { return _t.apply(this, arguments) }
It's a bit bother some to have to right every function like :
const myFunc = function () {}
You loose hoisting, and
function.nameReacted by Huan Li- addedSuggestionAn idea for TypeScriptAn idea for TypeScriptIn DiscussionNot yet reached consensusNot yet reached consensus
on Mar 24, 2015 124 remaining items
rbuckton commented
on Sep 21, 2015 ContributorAuthorMore actionsTako Little (@TakoLittle): The reason we don't do this today partially stems from how decorators are composed. Decorators follow the same principals as Mathematical function composition, where (f ∘ g)(x) is composed as f(g(x)). In the same sense, it can be thought that:
@F @G class X {}
Is approximately:
F(G(X))
The compositionality of decorators breaks down when you decorate both the getter and the setter:
class C { @F set X(value) {} @G get X() {} }
How do
FandGcompose here? Is it based purely on document order (i.e.F(G(X)))? Are each set of decorators for the getter and the setter discrete, and then executed in document order (i.e.G(F(X)))? Dogetandsetimply any specific ordering (i.e. is thegetalways before thesetor vice versa)? Until we're 100% certain the most consistent approach that doesn't surprise users, or have a well documented approach that is part of the decorators proposal with at least stage 2 or better acceptance within ECMA-262, we feel it is best to be more restrictive and error here as it allows us to relax that restriction at a later date without introducing a breaking change that could easily go unnoticed and possibly result in unexpected behaviors at runtime.Ron Buckton (@rbuckton) thank you so much for detailed explanation
TS team great work!! ^^d- addedCommittedThe team has roadmapped this issueThe team has roadmapped this issue
on Dec 9, 2015 - addedES NextNew featurers for ECMAScript (a.k.a. ESNext)New featurers for ECMAScript (a.k.a. ESNext)and removedES7Relates to the ES7 SpecRelates to the ES7 Spec
on Feb 4, 2016 - addedFixedA PR has been merged for this issueA PR has been merged for this issueand removedSpecIssues related to the TypeScript language specificationIssues related to the TypeScript language specification
on Feb 20, 2016 Where is the documentation for this? and care to link the implementation commit?
Thanks.
EisenbergEffect commented
on Feb 20, 2016 More actionsMohamed Hegazy (@mhegazy) What is the status on the implementation of the latest version of the spec. I understand there are some changes there.
This issue tracked the original version of the proposal. since this is completed we are closing this issue. for any updates to the spec, we will log new issues and outline all the breaking changes. I do not think the proposal is at a place now to be ready for us to jump on it. We are working closely with Yehuda Katz (@wycats) on the new proposal.
Omeid Matten (@omeid), you can find documentation at https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Decorators.md
EisenbergEffect commented
on Feb 23, 2016 More actionsMohamed Hegazy (@mhegazy) Thank you for the update. I'd love to stay informed. When you create the new issue for the spec update, please link it here so I can be notified and follow. The Aurelia community makes heavy use of decorators and we'll want to synchronize with both TypeScript and Babel on the update. Again, thanks for the great work the TS team is doing!
Reacted by AlexFunction decoration is need of course.
Are there also plans for decorating of other objects in the code?Reacted by majo44, Alex Sharov, Braden Snell, vandalouze, ikokostya, Umed Khudoiberdiev, Alec Merdler, Adam Pietrasiak, fenduru and Huan Li- locked and limited conversation to collaborators
on Jun 18, 2018
Decorator targets:
Class constructor
desugars to:
Methods
desugars to:
Static method
desugars to:
Properties
desugars to:
Method/Accessor formal parameter
desugars to:
Where the __decorate is defined as:
Decorator signatures:
A valid decorator should be:
Notes:
var x = dec(function () { });