Making a struct optional
See original GitHub issueHello, if I want to make the author field optional, what do I have to do with this basic piece of code ?
const Article = struct({
id: 'number',
title: 'string',
created_at: 'date',
published_at: 'date?',
author: User,
})
What I would like to do is just add the question mark sign.
Thanks.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Swift Initialize Struct with optional stored properties
I'd like to use Structs to represent a business but I have no idea in advance which combination of properties any specific business...
Read more >Can Swift Structs have optional stored properties? - Treehouse
Is there a way to define an optional stored property on a swift struct? Something like:
Read more >Making the most of optionals - Hacking with Swift
One way to solve this is to box the property in a class, then wrap that in an optional. Classes are reference types...
Read more >Optional field in struct - General Usage - Julia Discourse
It makes it easy define structs with optional keyword arguments, i.e. default values for fields that are not explicitly given. For example b ......
Read more >solidity - Make a struct member optional when initializing struct
I have a struct where I don't want the value of the address[] arrays to be intialised. But I get a error expected...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Found the answer in the unit tests, here is the way to do it:
https://github.com/ianstormtaylor/superstruct/blob/master/test/fixtures/object-lists/property-optional.js#L6
or another way
Maybe you will have to update the docs.
Documented now!