microsoft / microsoft/TypeScript
Conditional (using extends) parametrised type inference seems to be inconsistent
Offen
@ahejlsberg arbeitet bereits daran.
Seit 30.8.2024.
Needs Investigation
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 Search Terms
repo:microsoft/inconsistent typing with extends and parametrised types
repo:microsoft/TypeScript inconsistent typing with extends
repo:microsoft/TypeScript inconsistent conditional typing
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed all the FAQ for entries.
⏯ Playground Link
💻 Code
class Clunk<N extends string> {}
class SpecialClunk<N extends string> extends Clunk<N> {
specialField = 'funkyfield';
}
type SpecialClunkExtendsClunk = SpecialClunk<any> extends Clunk<any> ? true : false; // true.
type ClunkExtendsSpecialClunk = Clunk<any> extends SpecialClunk<any> ? true : false; // true.
export type SomeClunk<T extends 'normal' | 'special', N extends string> = T extends 'normal'
? Clunk<N>
: T extends 'special'
? SpecialClunk<N>
: never;
type SpecialExtendsNormal = 'special' extends 'normal' ? true : false; // false.
type NormalExtendsSpecial = 'normal' extends 'special' ? true : false; // false.
// Use of type here to be compatible with generic params.
export type P1<T extends 'normal' | 'special'> = {
clunk: SomeClunk<T, 'foo'>;
};
type P1normal = P1<'normal'>; // type P1normal = { clunk: Clunk<"foo">; }
type P1special = P1<'special'>; // type P1special = { clunk: SpecialClunk<"foo">; }
type P1NormalDoesNotExtendsSpecial = P1normal extends P1special ? true : false; // false
type P1SpecialExtendsNormal = P1special extends P1normal ? true : false; // true
// Below is false, but expected to be true, like P1SpecialExtendsNormal *** BUG?
type P1SpecialExtendsNormalNowFalse = P1<'special'> extends P1<'normal'> ? true : false; // false
🙁 Actual behavior
P1SpecialExtendsNormal is true
P1SpecialExtendsNormalNowFalse is false
🙂 Expected behavior
P1SpecialExtendsNormal is true
P1SpecialExtendsNormalNowFalse is true
Additional information about the issue
I can't tell if this might be related to https://github.com/microsoft/TypeScript/issues/44945
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.