Closed qpre closed 8 years ago
Having my type declared as:
// myType.es6 export type Type = { id: number, };
I'd want to use it this way:
// myImplem.es6 import type {Type} from 'myTypeFile'; export function get(id) : Type { let j: Type = { id }; // do stuff return j; }
but these respectively transform into:
// myType.js "use strict"; exports.__esModule = true;
// myImplem.js 'use strict'; exports.__esModule = true; exports.get = get; function get(id) { var j = { id: id. }; if (!(j instanceof Type)) throw new TypeError('Function \'get\' return value violates contract, expected Type got ' + (j === null ? 'null' : j instanceof Object && j.constructor ? j.constructor.name : typeof j)); return j; }
Which quite logically produces this error at runtime.
ReferenceError: Type is not defined
Any idea of whether it is more likely to be an error in my configuration or a bug in the tool ?
It's a shortcoming of babel which will be addressed in v6 - babel doesn't let us cross module boundaries yet. When it does we'll start supporting typedefs
closing because this is a dupe of #2
Thanks.
Having my type declared as:
I'd want to use it this way:
but these respectively transform into:
Which quite logically produces this error at runtime.
Any idea of whether it is more likely to be an error in my configuration or a bug in the tool ?