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

Feature request: opt-in Assert<T> type for arguments #222

Open
2 of 10 tasks
jedwards1211 opened this issue Jan 14, 2019 · 0 comments
Open
2 of 10 tasks

Feature request: opt-in Assert<T> type for arguments #222

jedwards1211 opened this issue Jan 14, 2019 · 0 comments

Comments

@jedwards1211
Copy link
Collaborator

This is a:

  • Bug Report
  • Feature Request
  • Question
  • Other

Which concerns:

  • flow-runtime
  • babel-plugin-flow-runtime
  • flow-runtime-validators
  • flow-runtime-mobx
  • flow-config-parser
  • The documentation website

This is a PR I'd like to work on someday after fixing more important issues.

What is the current behaviour?

I typically use babel-plugin-flow-runtime with "optInOnly": true for API argument validation. The code looks like the following:

// @flow
// @flow-runtime enable

import reify from 'flow-runtime'
import type {Type} from 'flow-runtime'

type InitUserAttributes = {
  email: string,
  password: string,
}
type InitUserAttributesType = (reify: Type<InitUserAttributes>)

export function createUser(attributes: InitUserAttributes) {
  InitUserAttributesType.assert(attributes)
  ...
}

What is the expected behaviour?

It would be nice if I could shorten this to

// @flow
// @flow-runtime enable

import type {Assert} from 'flow-runtime'

type InitUserAttributes = {
  email: string,
  password: string,
}

export function createUser(attributes: Assert<InitUserAttributes>) {
  ...
}

Basically type Assert<T> = T, but babel-plugin-flow-runtime would insert runtime assertions for any arguments using the Assert type.

Which package versions are you using?

babel-plugin-flow-runtime: 0.18.0

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

No branches or pull requests

1 participant