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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "oneOf" to TypeScript typings #168

Merged
merged 1 commit into from Aug 10, 2018
Merged

Add support for "oneOf" to TypeScript typings #168

merged 1 commit into from Aug 10, 2018

Conversation

LinusU
Copy link
Collaborator

@LinusU LinusU commented Aug 10, 2018

Until variadic kinds land in TypeScript, we have to type out each arity manually.

For now, I have only done 2, 3, and 4. I don't know how common it is with larger, but I think the easiest is to wait for an issue to be filed 馃槃

ping @cstruct 鉂わ笍


/* Plain schema */
<Schema extends AnySchema> (schema: Schema, options?: any): Validator<Schema>
createFilter<Schema extends AnySchema> (schema: Schema, options?: any): Filter<Schema>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to suggestions on the indentation here 馃槅

Opted to try and align the validator and filter as much as possible, to reduce the risk for them having subtle differences.

})

if (overengineeredColorValidator(input)) {
if (input !== 'red' && input !== 'pink' && input !== 'green' && input !== 'olive' && input !== 'blue' && input !== 'teal' && input !== 'yellow') assertType<'cream'>(input)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do a negated includes to make all of these a bit easier to read?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript won't be able to extract type information from that, unfortunately.

@LinusU LinusU merged commit 4bec868 into master Aug 10, 2018
@LinusU LinusU deleted the ts-oneof branch August 10, 2018 17:58
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.

None yet

2 participants