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

Fails with default values of destructured object #118

Closed elado closed 8 years ago

elado commented 8 years ago
function x({y = "hello"}: {y: string}) {
}

Error:

SyntaxError: Unexpected token =

phpnode commented 8 years ago

Fixed in 3.7.0

okonet commented 8 years ago

I'm using 3.8.0 and see the following compiling error:

Property argument of UnaryExpression expected node to be of a type ["Expression"] but instead got "AssignmentPattern"

for the following code:

const FormattedDuration = ({ duration, specifier = ',d' }: {
    duration: number,
    specifier: string
}) => {...}
okonet commented 8 years ago

Having it written like:

type Props = {
    duration: number,
    specifier: string,
    svg: ?boolean
}

const FormattedDuration = ({ duration, specifier = ',d', svg = false }: Props) => {...}

shows me

ERROR in ./app/components/FormattedDuration/FormattedDuration.js
Module parse failed: [...]/node_modules/babel-loader/index.js?{"presets":["react-hmre"],"plugins":["babel-plugin-typecheck"]}!/.../app/components/FormattedDuration/FormattedDuration.js Shorthand property assignments are valid only in destructuring patterns (29:47)
You may need an appropriate loader to handle this file type.
|     var svg = _arg$svg === undefined ? false : _arg$svg;
| 
|     if (!Props({ duration: duration, specifier = ',d', svg = false })) {
|         throw new TypeError('Value of "{\n  duration,\n  specifier = \',d\',\n  svg = false\n}" violates contract.\n\nExpected:\nProps\n\nGot:\n' + _inspect({ duration: duration, specifier = ',d', svg = false }));
|     }
patrikholcak commented 8 years ago

Any news on this? I’m getting the same error as @okonet when using param destructuring