-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add Extends #14
Add Extends #14
Conversation
Hi @garronej, this PR is complete, however, I marked it as draft because of the following questions:
TODO: I will add the missing docs https://docs.tsafe.dev/main/extends |
I aligned the behavior of the type |
Oh boy, I've found some kind of unexpected behavior of TypeScript: type Extends<T1, T2> = T1 extends T2 ? true : false;
type A1 = never extends any ? true : false // = true
type B1 = Extends<never, any> // = never ❌
type A2 = any extends never ? true : false // = boolean
type B2 = Extends<any, never> // = boolean ✅
type A3 = never extends 1 ? true : false // = true
type B3 = Extends<never, 1> // = never ❌
type A4 = 1 extends never ? true : false // = false
type B4 = Extends<1, never> // = false ✅
type A5 = never extends never ? true : false; // = true
type B5 = Extends<never, never> // = never ❌ The following does not solve the problem: type Extends<T1, T2> = T1 extends never ? true : T1 extends T2 ? true : false; However, the following does solve the problem: type Extends<T1, T2> = StrictEquals<T1, never> extends true ? true : T1 extends T2 ? true : false; I will provide a fix with another commit... |
Hi @danieldietrich,
LGTM
It's probably a bug but let's leave it since I have no time to investigate right now. It's maybe on purpose.
<3
Thanks you for taking this so seriously! |
Ok, now I consider the type logic to be complete. I will mark it as ready for review. |
assert<Equals<Extends<A, A>, true>>(); | ||
} | ||
|
||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a little remark regarding the following tests - I intentionally added duplications because it is important in the respective context to understand the whole picture. Overlapping tests do not really harm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got you!
Solves #13