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

Define object with props as an optional argument #39

Closed alex35mil closed 9 years ago

alex35mil commented 9 years ago

Thanks for this plugin! I sleep much better now :)

I have 3 questions. Will split them in 3 issues. Here is first one.

Is it possible to define object with props as an optional argument?

export default function dummiesReducer(
  $state: $Map = $initialState,
  {
    type,
    index,
    errors,
  } : {
    type  : string,
    index : ?Array<number>,
    errors: ?{ code: number, data: Object }, // <--- if arg is passed - check its props
  }
) {
  // ...
}
phpnode commented 9 years ago

@alexfedoseev thanks for the bug reports. Our support for object props / default args is not very good at the moment - if it works, it's mostly by happy accident. Really this whole plugin will need a refactor when babel6 comes out and I'd really like to tackle this then.

alex35mil commented 9 years ago

if it works, it's mostly by happy accident

Haha, waiting for Babel 6 then. Thanks for great work!

alex35mil commented 9 years ago

Looks like this workaround works:

function({ errors } : { errors: void | { code: number, data: Object } }) {}
phpnode commented 9 years ago

Haha, waiting for Babel 6 then.

It just came out today, but I'm waiting a day or two for things to calm down before starting with it.

alex35mil commented 9 years ago

Great, thanks! :+1: