Skip to content

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