microsoft / microsoft/TypeScript

Results of conditional types are not comparable (regression)

Abierto
#30,049 1 comentario 0 reacciones 1 asignado Ver en GitHub

@weswigham ya está trabajando en esto.

Desde el 27/2/2019.

Needs Investigation
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

@RyanCavanaugh @weswigham @ahejlsberg Caused by #27697

TypeScript Version: 3.4.0-dev.20190222

Search Terms:

Code

type Falsy = undefined | false | 0 | '' | null | void;

type TEq<T, U> = [T] extends [U] ? [U] extends [T] ? true : false : false;
type If<S, T, U> = S extends Falsy ? U : T;

type StrictExtract<T, U> = T extends U ? U extends T ? T : never : never;
type StrictExclude<T, U> = T extends StrictExtract<T, U> ? never : T;

type ExcludeProp<T, V> =
  { [Q in { [P in keyof T]: If<TEq<V, never>, T[P] extends never ? never : P, If<Includes<T[P], V>, never, P>>; }[keyof T]]: T[Q]; };
type DeepExcludeProp<T, V, E extends object | undefined | null = never> =
  T extends E ? T :
  T extends V ? never :
  T extends readonly any[] | Function ? T :
  T extends object ? ExcludeProp<{ [Q in { [P in keyof T]: If<TEq<V, never>, T[P] extends never ? P : P, If<Includes<T[P], V>, T[P] extends E ? P : never, P>>; }[keyof T]]: StrictExclude<DeepExcludeProp<T[Q], V, E>, {}>; }, never> :
  T;
type Includes<T, U> = true extends (T extends U ? true : never) ? true : false;

type AD = { a: boolean; b: { a: boolean; b: boolean[]; c: undefined; d: undefined[]; e: boolean | undefined; f: Array<boolean | undefined>; }; c: { a: undefined; }; };

type a = DeepExcludeProp<AD, undefined, AD['b']>;
type b = ExcludeProp<AD, AD['c']>;
type c = {
  a: boolean;
  b: {
    a: boolean;
    b: boolean[];
    c: undefined;
    d: undefined[];
    e: boolean | undefined;
    f: Array<boolean | undefined>;
  };
};
type d = TEq<a, c>;
type e = TEq<b, c>;
type f = TEq<a, b>;

Expected behavior:

type d = TEq<a, c>; // true
type e = TEq<b, c>; // true
type f = TEq<a, b>; // true

Actual behavior:

type d = TEq<a, c>; // true
type e = TEq<b, c>; // true
type f = TEq<a, b>; // false

Playground Link:

Related Issues: #30047

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.