Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeEq false positive #6

Open
sirian opened this issue May 29, 2019 · 3 comments
Open

TypeEq false positive #6

sirian opened this issue May 29, 2019 · 3 comments

Comments

@sirian
Copy link

sirian commented May 29, 2019

TypeEq<[number, ...number[]], number[]> is true, but should be false

export type TypeEq<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;

declare const foo: [number, ...number[]];
declare const bar: number[];

const test: TypeEq<typeof foo, typeof bar> = false;

const foobar: typeof foo = bar;
const barfoo: typeof bar = foo;

image

playground

@sirian
Copy link
Author

sirian commented May 29, 2019

Consider this playground

type And<T extends any[]> = T extends true[] ? true : false;

type IsExact<A, B> = [A, B] extends [B, A] ? true : false; 

export type TypeEq<A, B> = And<[
  IsExact<A, B>,
  IsExact<(<T>() => T extends A ? 1 : 2), (<T>() => T extends B ? 1 : 2)>
  ]>;

type MustBeTrue<T extends true> = T;
type MustBeFalse<T extends false> = T;

type Test = [
    MustBeTrue<TypeEq<1, 1>>,
    MustBeTrue<TypeEq<[...1[]], 1[]>>,
    MustBeTrue<TypeEq<[...0[]], 0[]>>,
    MustBeFalse<TypeEq<[0?, ...0[]], false[]>>,
    MustBeFalse<TypeEq<[0?, ...(0 | undefined)[]], (0 | undefined)[]>>,
    MustBeFalse<TypeEq<[1, ...0[]], 0[]>>
];

@kgtkr
Copy link
Owner

kgtkr commented Jun 18, 2019

This is a very strange behavior.
It may be a bug of TypeScript

@kgtkr
Copy link
Owner

kgtkr commented Jun 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants