codemix / babel-plugin-typecheck

Static and runtime type checking for JavaScript in the form of a Babel plugin.
MIT License
886 stars 44 forks source link

Referencing a variable in ENUM produces an error about instanceof check #149

Closed gajus closed 7 years ago

gajus commented 8 years ago
export const DATETIME = 'datetime';
export const DATE = 'date';
export const TIME = 'time';

type TypeMode = DATETIME | DATE | TIME;

export const format = (date: Date, mode: TypeMode = DATETIME): string => {
    // ..
};

format('...', DATETIME);

Is giving an error:

     TypeError: Expecting a function in instanceof check, but got datetime
      at TypeMode (format.js:14:17)
      at format (format.js:19:35)
      at Context.<anonymous> (format.spec.js:13:16)
      at callFn (c:\runnable.js:315:21)
      at Test.Runnable.run (c:\runnable.js:308:7)
      at Runner.runTest (c:\runner.js:422:10)
      at c:\runner.js:533:12
      at next (c:\runner.js:342:14)
      at c:\runner.js:352:7
      at next (c:\runner.js:284:14)
      at Immediate._onImmediate (c:\runner.js:320:5)
phpnode commented 8 years ago

I think you need to use typeof here:

export const DATETIME = 'datetime';
export const DATE = 'date';
export const TIME = 'time';

type TypeMode = typeof DATETIME | typeof DATE | typeof TIME;
phpnode commented 7 years ago

Closing in favour of flow-runtime.