Microsoft/TypeScript
在 GitHub 查看【bug】ThisType is invalid when using param on generic object
Open
#52,969 创建于 2023年2月25日
BugDomain: This-TypingHelp Wanted
仓库指标
- Star
- (48,455 star)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 9 个 PR)
描述
Bug Report
🔎 Search Terms
ThisType Object Generic
🕗 Version & Regression Information
I was unable to test this on prior versions because I was not using this feature previously
⏯ Playground Link
Playground link with relevant code
💻 Code
type ILifetime = {
onShareTimeline: () => string
}
function createObject<D>(obj: D & ILifetime & ThisType<D>) {
console.warn(obj)
}
// working
createObject({
title: 'demo',
onShareTimeline() {
return ''
}
})
// not working
createObject({
title: 'demo',
onShareTimeline() {
return this.title
}
})
🙁 Actual behavior
The generic type is broken
🙂 Expected behavior
The generic type should contain the object properties as those are finally included into the result