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

Add optional #628

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

thewilkybarkid
Copy link
Contributor

@thewilkybarkid thewilkybarkid commented Jan 28, 2022

This adds optional to the Decoder, Encoder and Codec modules, which handles conversion between undefined and Option.

This is a little different to optionFromNullable in that it only works with undefined and not null (optionFromNullable decodes from both, and encodes to null (gcanti/io-ts-types#166)).

Refs #542 (comment).

@thewilkybarkid
Copy link
Contributor Author

thewilkybarkid commented Mar 31, 2022

Just tried this with the json Encoder from #638 (as a property in a struct) and found that the undefined is not assignable to Json (i.e. it's not quite the same as not existing in the type).

@thewilkybarkid
Copy link
Contributor Author

Options I can see are to make the JsonRecord type have undefined properties, or to use something like microsoft/TypeScript#12400 (comment) on the struct types (i.e. to make properties that can have undefined as a value optional).

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

Successfully merging this pull request may close these issues.

2 participants