Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I export a flow interfaces using CommonJS?

Tags:

flowtype

I'm not sure if my build is good or not, but in my package.json, I have

"scripts": {
    "build": "flow-remove-types src/ -d build/",

And I have a types/sentence.js, which has:

// @flow

type SentenceObject = {
  foo: number,
  bar: boolean,
  baz: string,
};

module.exports = {
  SentenceObject
};

And in my library file, I have:

const { SentenceObject } = require('../interfaces/sentence');

The problem, when I do yarn build is:

src/interfaces/sentence.js
 ↳ Syntax Error: Unexpected token, expected = (3:27)
   2:  export type SentenceObject {

What am I doing incorrectly?

like image 768
Shamoon Avatar asked Oct 29 '18 13:10

Shamoon


1 Answers

There seems to no CommonJS style for require flow types. Instead you can use export/import as suggested in docs. So in your case it might be something like:

types/sentence.js:

// @flow
export type SentenceObject = {
  foo: number,
  bar: boolean,
  baz: string,
};

notice the export keyword.

And in your library file you can use import type {...} from '':

import type { SentenceObject } from '../interfaces/sentence';
like image 168
Alex Avatar answered Nov 13 '22 04:11

Alex