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

Consider adding type coercion #37

Open
notatestuser opened this issue Sep 14, 2016 · 3 comments
Open

Consider adding type coercion #37

notatestuser opened this issue Sep 14, 2016 · 3 comments

Comments

@notatestuser
Copy link

It'd be nice to be able to coerce convertible types to other types.

const PersonRecord = Record({
  id: String,
  phone: Coerce(Union(Number, String), String),
}, 'Person');

In this hypothetical example if we did the following:

const p1 = PersonRecord({ id: 0, phone: 12318001800 });

accessing p1.phone would give us a string.

We'd have to keep a map of how we get from one type to others. This could be hard-coded or supplied at run-time.

@stutrek
Copy link
Member

stutrek commented Sep 14, 2016

I like it because it's explicit

@notatestuser
Copy link
Author

I could have a stab at implementing this if you think it would be a worthwhile feature.

@stutrek
Copy link
Member

stutrek commented Sep 19, 2016

I think people will like it. I think @udnisap implemented something similar but didn't put it in a PR.

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