Microsoft/TypeScript
Voir sur GitHubUsing Parameters in a class member function gets incorrect result while all parameters are optional.
Open
#53 541 ouverte le 27 mars 2023
BugDomain: check: Type InferenceHelp 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
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
5.0.2 and 4.9.5
- 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
Playground link with relevant code
💻 Code
class T {
// fn(): void;
// fn( name?: string ): void;
fn( name?: string, sex?: number ): void {}
}
class M<X extends T> {
constructor( public m: X ) {}
fn( ...args: Parameters<X['fn' ]> ) {
this.m.fn( ...args );
}
}
function fn2( ...args: Parameters<T[ 'fn' ]> ) {
new T().fn( ...args );
}
🙁 Actual behavior

The fn method in class M has similar code with the global function fn2, but it get errors.
The error message disappears if I add function overload ( uncomment line 3 & 4 in playground ).