microsoft / microsoft/TypeScript
Conditional (using extends) parametrised type inference seems to be inconsistent
Aperta
@ahejlsberg ci sta già lavorando.
Dal 30/8/2024.
Needs Investigation
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.