Microsoft/TypeScript
GitHub ã§èŠã`this` parameter not correctly inferred when unrelated type parameter has no inference candidates
Open
#56,024 opened on 2023幎10æ8æ¥
BugDomain: This-TypingHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
generics bug
ð Version & Regression Information
- This is a crash
- This changed between versions ______ and _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⯠Playground Link
No response
ð» Code
function test<
Data1 extends Record<string, number>,
Data2 extends Record<string, ()=>number>,
Func extends Record<string, (this: Data2)=>void>,
>(options: {
data1?: Data1,
data2: Data2,
func: Func,
}) {
console.log(options);
};
test({
data1: {
a1: 1
},
data2: {
a2 () {return 2;}
},
func: {
f1 () {
this.a2; // this.a2 has no type hints
}
}
});
ð Actual behavior
this.a2 has no type hints
ð Expected behavior
this.a2 has type hints
Additional information about the issue
If you comment out data1, then type hints appear
function test<
Data1 extends Record<string, number>,
Data2 extends Record<string, ()=>number>,
Func extends Record<string, (this: Data2)=>void>,
>(options: {
data1?: Data1,
data2: Data2,
func: Func,
}) {
console.log(options);
};
test({
// data1: {
// a1: 1
// },
data2: {
a2 () {return 2;}
},
func: {
f1 () {
this.a2; // If you comment out data1, then type hints appear
}
}
});