flow-runtime
flow-runtime copied to clipboard
Getting types from a node module
This is a:
- [ ] Bug Report
- [ ] Feature Request
- [x] Question
- [ ] Other
Which concerns:
- [x] flow-runtime
- [x] 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:
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?
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.