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

Embedded optional types? #83

Closed
jez9999 opened this issue Nov 1, 2017 · 2 comments
Closed

Embedded optional types? #83

jez9999 opened this issue Nov 1, 2017 · 2 comments

Comments

@jez9999
Copy link

jez9999 commented Nov 1, 2017

The documentation suggests making optional members of a type using intersection:

const MandatoryRunSettings = t.interface({
	appName: FilledString,
});

const OptionalRunSettings = t.partial({
	shortAppName: FilledString,
});

const RunSettings = t.intersection([MandatoryRunSettings, OptionalRunSettings]);

However this can start to look a bit ugly if you have lots of members of a type and want related members to be next to one another. Could we implement an "optional" tag for types so that we can just associate that data with the type? Then we could say something like:

const RunSettings = t.interface({
	appName: FilledString,
	shortAppName: t.OptionalType<FilledString>,
});
@gcanti
Copy link
Owner

gcanti commented Nov 1, 2017

AFAIK is not possible at the field level, see here for an explanation #56

@gcanti gcanti closed this as completed Nov 1, 2017
@jez9999
Copy link
Author

jez9999 commented Nov 1, 2017

I posted a comment in #56, please respond. I still don't see what the problem is with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants