Side effect of decorator

未关闭
#56,000 9 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@rbuckton 已经在做这个了。

开始于 2023年10月5日。

评估

这个 Issue 还没有评估数据。

描述

Bug Domain: Decorators Needs Investigation
🔎 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
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

主要语言
Go
星标
111k
派生
14.4k
平均合并
1 天 19 小时
30 天内合并 PR
117

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/TypeScript 的其他 Issue

查看 microsoft/TypeScript 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。