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

Subtyping is not a transitive relation #47499

Closed
masaeedu opened this issue Jan 19, 2022 · 2 comments
Closed

Subtyping is not a transitive relation #47499

masaeedu opened this issue Jan 19, 2022 · 2 comments

Comments

@masaeedu
Copy link
Contributor

masaeedu commented Jan 19, 2022

Sorry about not filling out all the forms, not really using TypeScript actively and don't feel like doing that, but I was surprised by this and thought I'd post on the off chance that you would be too.

type x = <a extends string | boolean>(a: a) => a extends string ? string : a extends boolean ? boolean : a extends string | boolean ? string | boolean : TypeError
type y
  = ((a: string) => string)
  & ((a: boolean) => boolean)
  & ((a: string | boolean) => string | boolean)
type z = {
  (a: string): string
  (a: boolean): boolean
  (a: string | boolean): string | boolean
}

type isSubtypeOf<a, b> = a extends b ? true : false

type xIsSubtypeOfy = isSubtypeOf<x, y> // true
type yIsSubtypeOfz = isSubtypeOf<y, z> // true
type xIsSubtypeOfz = isSubtypeOf<x, z> // false

Here's a playground link: https://www.typescriptlang.org/play?#code/C4TwDgpgBAHlC8UA8BDKEbAgOwCYGcp9gAnAS2wHMoAfKAIwHtGAbCFbAPgAoUAuKCgCUCToPSYcBIqQrUA-DPJUoAtBix5CTVu2xRFOth1XiNUwsWXU6RvQaVzaDZsf0CAKuAgBREiUYSAChQSCgQIKgEKG5eASs5EXgxBKohSKgAMhi4l10OJLE7Aozs2P5HFVtXPULKmzy3dNDoAC9ogG8M3NTKIXjZKm6K4ux+xr1hgetnUfHe2ZqOIIBfIJDvKDJ8AGUAV3oWgHkAM1QAGgYxRHVJLQYHUj3oAROUFnwIdZbYAEldg7HE4gaLbfaHbynJAwS4gTgbMIgf7goHtRBgwGQs4gS6teE-GDIzGQU5orYAiEks4wqB4oA

@jcalz
Copy link
Contributor

jcalz commented Jan 19, 2022

#42479

#47331 (comment)

@masaeedu
Copy link
Contributor Author

@jcalz Cool, thanks for the pointer.

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