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

Swap arguments order and add currying for validation functions? #461

Closed
vaderkos opened this issue Aug 24, 2020 · 4 comments
Closed

Swap arguments order and add currying for validation functions? #461

vaderkos opened this issue Aug 24, 2020 · 4 comments
Labels
✶ breaking Changes that would mean a breaking API change improvement ⚑ pending Pull requests that are waiting on something else

Comments

@vaderkos
Copy link

It would be great if validation functions like is, assert, coerce, validate supported currying and had swapped arguments order.

In that way there would a bit more ways to use superstruct, so bound function can be easily prepared.

import { assert, number, string, StructType } from 'superstruct'

export const ArticleStruct = object({
  id: number(),
  title: string()
})

export type Article = StructType<typeof ArticleStruct>

export const assertArticle = assert(ArticleStruct)

@mikestopcontinues
Copy link

I like this. In the meantime, you can use the babel implementation of the partial operator to get what you want without wrapper functions.

@ianstormtaylor ianstormtaylor added the question Issues that are usage questions label Nov 20, 2020
@ianstormtaylor
Copy link
Owner

I need to document this better, but you can already use:

ArticleStruct.assert(data)

Instead of:

assert(data, ArticleStruct)

I'm not sure we gain much more with currying?

The reason to have the helpers as functional ones at all is unfortunately because we're pushing the limits of what TypeScript is capable of, and TypeScript will error when using Struct.assert(data), which I'm fairly sure will also error when using the curried method. (Here's the TypeScript issue tracking the limitation: microsoft/TypeScript#34596)

@ianstormtaylor
Copy link
Owner

I take it back, I do see the value in offering currying. Once that upstream TypeScript issue is fixed I'm down to have a breaking change to swap the order of those arguments and add currying. I don't want to do it until then though because I don't want to end up with more parts of the codebase that only work when not using TypeScript.

@ianstormtaylor ianstormtaylor added improvement ⚑ pending Pull requests that are waiting on something else and removed question Issues that are usage questions labels Nov 24, 2020
@ianstormtaylor ianstormtaylor added the ✶ breaking Changes that would mean a breaking API change label Feb 11, 2021
@arturmuller
Copy link
Collaborator

It seems like the TS issue is not going to be solved. Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✶ breaking Changes that would mean a breaking API change improvement ⚑ pending Pull requests that are waiting on something else
Projects
None yet
Development

No branches or pull requests

4 participants