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

Definition of Equal? #153

Closed
Means88 opened this issue Sep 6, 2020 · 2 comments
Closed

Definition of Equal? #153

Means88 opened this issue Sep 6, 2020 · 2 comments

Comments

@Means88
Copy link

Means88 commented Sep 6, 2020

type A = { a: string; b: string };
type B = { a: string };
type C = { b: string };

// type Equal<X, Y> = <T>() => (T extends X ? 1 : 2) extends <T>() => (T extends Y ? 1 : 2) ? true : false;
/** --- Error --- */
type E0 = Expect<Equal<A, B & C>>; // Type 'false' does not satisfy the constraint 'true'.(2344)
/** ------------- */
type E1 = Expect<A extends B & C ? true : false>;
type E2 = Expect<B & C extends A ? true : false>;

microsoft/TypeScript#27024 (comment)

...which fails because the definition of "identical" doesn't allow an intersection type to be identical to an object type with the same properties.

Is there any negative case T that T extends A different from T extends B & C?

@Means88
Copy link
Author

Means88 commented Sep 6, 2020

related #9 (comment)

@antfu
Copy link
Member

antfu commented Sep 7, 2020

Thanks, I made an update to the utils, adding a new util Alike.

Equal refers to "Strictly equal" while Alike refers to "Strcuturely equal". So in this case Expect<Alike<A, B & C>> would be true while Expect<Equal<A, B & C>> will still fail.

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