microsoft / microsoft/TypeScript
Conditional (using extends) parametrised type inference seems to be inconsistent
Abierto
@ahejlsberg ya está trabajando en esto.
Desde el 30/8/2024.
Needs Investigation
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔎 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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.