Microsoft/TypeScript
Voir sur GitHub`this` parameter not correctly inferred when unrelated type parameter has no inference candidates
Open
#56 024 ouverte le 8 oct. 2023
BugDomain: This-TypingHelp Wanted
Métriques du dépôt
- Stars
- (48 455 stars)
- Métriques de merge PR
- (Merge moyen 6j 17h) (9 PRs mergées en 30 j)
Description
🔎 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
}
}
});