-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Another patch for Nominal Type #570
Comments
The type inference works better for me in this scenario: type A = string & { _type: 'A' };
type B = string & { _type: 'B' };
type C = string & { _type: 'C' };
type D = A | B | C;
const f = (a: A, b: B, c: C) => a || b || c;
// Infers: const f: (a: A, b: B, c: C) => D ✅ enum ABrand { _ = '' }
type A = string & ABrand;
enum BBrand { _ = '' }
type B = string & BBrand;
enum CBrand { _ = '' }
type C = string & CBrand;
type D = A | B | C;
const f = (a: A, b: B, c: C) => a || b || c;
// Infers: const f: (a: A, b: B, c: C) => C 💔 |
An alternative, more similar to your Interface related one is: type A = string & { _aBrand: any; }
type B = string & { _bBrand: any; }
type C = string & { _cBrand: any; }
type D = A | B | C;
const f = (a: A, b: B, c: C) => a || b || c;
// Infers: const f: (a: A, b: B, c: C) => D ✅ |
👍 Needs to be added as |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this article, as a introduction to another thing, the author shows another kind of patch to use nominal types:
It worked better for me with type inference than your approach with enums.
Do you think that is a good idea to add this alternative? or is there a well known issue with this approach?
The text was updated successfully, but these errors were encountered: