microsoft / microsoft/TypeScript
Side effect of decorator
Open
@rbuckton is already working on this.
Since Oct 5, 2023.
Bug
Domain: Decorators
Needs Investigation
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
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
💻 Code
const FieldDecorator = (target: undefined, context: ClassFieldDecoratorContext) => {} // do nothing
class Parent {
constructor(arg1: string, arg2: string, arg3: string) {
// @ts-ignore
this.prop1 = arg1
// @ts-ignore
this.prop2 = arg2
// @ts-ignore
this.prop3 = arg3
}
}
class Child extends Parent {
prop1!: string
prop2!: string
@FieldDecorator
prop3!: string
}
const a = new Child('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
const obj = {
prop1: "11"
prop2: "22"
prop3: "33"
}
Additional information about the issue
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.