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

Getting types from a node module #202

Open
3 of 10 tasks
mxstbr opened this issue Apr 9, 2018 · 1 comment
Open
3 of 10 tasks

Getting types from a node module #202

mxstbr opened this issue Apr 9, 2018 · 1 comment

Comments

@mxstbr
Copy link

mxstbr commented Apr 9, 2018

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

I'm trying to create a validation function for raw DraftJS content state to be able to validate from our API that incoming objects have the right shape. (ref https://github.com/withspectrum/spectrum/issues/2792)

This is what I imagined I'll be doing:

// @flow
import t, { reify } from 'flow-runtime';
import type { Type } from 'flow-runtime';
import type { RawDraftContentState } from '../node_modules/draft-js/lib/RawDraftContentState.js.flow';

const RawDraftContentStateType = (reify: Type<RawDraftContentState>);

function draftValidate(input: ?RawDraftContentState): bool {
  const validation = t.validate(RawDraftContentStateType, input);
  console.log(validation.errors);
  return validation.hasErrors();
}

export default draftValidate;

Unfortunately, this throws an "Unexpected token import" error:

screen shot 2018-04-09 at 13 56 25

I pushed the repo as-is up to GitHub here: https://github.com/withspectrum/draft-js-validate Any hints how I can make this work?

@mxstbr
Copy link
Author

mxstbr commented Apr 9, 2018

Just to note, I also tried to generate a JS file from the Draft types with the CLI like so: flow-runtime generate ./node_modules/draft-js/lib > src/draft-types.js Unfortunately, that outputs an empty file.

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