microsoft / microsoft/TypeScript
Decorated function parameter types are not inferred
未关闭
@rbuckton 已经在做这个了。
开始于 2023年6月19日。
Needs Investigation
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 117
描述
Bug Report
When decorating a class method, the argument types are not inferred from the decorator. When using the decorator method directly, without decorator syntax, the types are inferred correctly.
🔎 Search Terms
decorator, infer, type, argument
🕗 Version & Regression Information
- This happens for decorators introduced in 5.0
⏯ Playground Link
Playground link with relevant code
💻 Code
function decorate(f: (id: number) => void, context?: any): (id: number) => void { return f }
class Foo {
@decorate
one(id) { // Parameter 'id' implicitly has an 'any' type.(7006)
console.log(id as string)
}
two = decorate(function two(id) {
console.log(id as string) // Conversion of type 'number' to type 'string' may be a mistake… (2352)
})
}
let foo = new Foo();
foo.one("foo")
foo.two("foo") // Argument of type 'string' is not assignable to parameter of type 'number'.(2345)
🙁 Actual behavior
The parameter id for method one is inferred as any
🙂 Expected behavior
The parameter is inferred as number, similar to how it works when calling the decorated function directly for method two.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
评估
这个 Issue 还没有评估数据。