Skip to content

Side effect of decorator #56000

Description

🔎 Search Terms

"decorator" "field decorator" "side effect" "decorator side effect"

🕗 Version & Regression Information

  • This changed between versions 5.0 and 5.2
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about decorators

⏯ Playground Link

https://www.typescriptlang.org/play?#code/MYewdgzgLgBAYgSwKYBsAmARJoBOBDKEHGAXhgAoo8cBzJKALhgFcw0kAzBMJNAGhigwUJAA9GMAMIo8ECIlSZsRAkUngR4gJSkAfDADeAXwBQJ4DLkwACtSTDDJmIPDQczYIRzlqNAIxMbtw0Ar4ATIFQOMGhtADMkdFgNDoGTs4wAPSZMAACUBAAtAg0YERI6c5QABYIEAB0AA44II1+pDC+fpVZOflFJWU4FRkwNXVNLY1hHeE92XkFxaXlPeMNza1xs-Hpps6bbQCEicFmB1NhJzBByecwh3HXtzQmpuaWEFK16DBiImwvrZhg40hdWn5nlEzulDldTnd0rkFOgsLhVDhYVMngjXu8hNBOh0eAB3b4IdDkADkfj8VIEVLCYXpMCpcTiVK05lcIBQSHqKBANB8XIWeEmENIJDIrHYXB4aF6MAA6gAVOAmMUS6ZSsiM5lKgDyAGlNTlxY9dSw2JxuLwlWqNUA

💻 Code

constFieldDecorator=(target: undefined,context: ClassFieldDecoratorContext)=>{}// do nothingclassParent{constructor(arg1: string,arg2: string,arg3: string){// @ts-ignorethis.prop1=arg1// @ts-ignorethis.prop2=arg2// @ts-ignorethis.prop3=arg3}}classChildextendsParent{prop1!: stringprop2!: string
@FieldDecoratorprop3!: string}consta=newChild('11','22','33')console.log(a)// a.prop1 === undefined // WTF// a.prop2 === '22' // OK// a.prop3 === undefined // WTF

🙁 Actual behavior

the decorated property and the very first property are undefined despite the fact that they are given a value in the constructor

🙂 Expected behavior

a object should be equal to the following obj object

constobj={prop1: "11"prop2: "22"prop3: "33"}

Additional information about the issue

No response

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: DecoratorsThe issue relates to the decorator syntaxNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions