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

Optional properties #390

Merged
merged 2 commits into from
Jun 20, 2020

Conversation

thesunny
Copy link
Collaborator

The purpose of the PR is to make object() types with optional() values appear as optional properties on an object. e.g.

// given
const struct = object({ a: optional(string()) })

// it should return this type (the `?` being the key change)
type X = {
  a?: string | undefined
}

There is also a related change to package.json which adds a script watch:types. The purpose of this script is so that when there are changes to code, the TypeScript type definitions get updated. During the normal watch, type changes are not reflected. A better solution may be to add build:types as part of the watch script instead of in a separate watch:types script.

Stylistically, the type helpers are near the object code. There aren't any existing type helpers (at least in the code I saw) so the choice to locate the type helpers near the code is arbitrary. It may be preferable to place them in utils; however, the code isn't used anywhere else (ie. it's not shared) so I opted to put it right above the object code. Let me know if you prefer it elsewhere.

@thesunny
Copy link
Collaborator Author

thesunny commented Jun 20, 2020

@ianstormtaylor

This passes all tests on my computer but ci is failing. It's unclear as to why this is happening.

@ianstormtaylor
Copy link
Owner

This is amazing, thank you @thesunny! I'll try restarting the CI to see if that fixes it.

@ianstormtaylor ianstormtaylor merged commit 94cbd2a into ianstormtaylor:master Jun 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants