question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object destructing strips default values on typescript, errors on flow

See original GitHub issue

Sorry for bad title, but here is something I noticed after moving some variables into an object (hence why the first bit is wrong)

const test = {
  foo = {
    bar: 'baz'
  },
  foo = [
    'bar', 'baz'
  ]
}

This object isn’t correct (foo = instead of foo:), but instead of giving an error when formatting it turns into

const test = {
  foo,
  foo,
};

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
azzcommented, Jun 24, 2017

Raised this issue here: https://github.com/eslint/typescript-eslint-parser/issues/332

Seems this might be the right issue to track for flow: https://github.com/facebook/flow/issues/183 (Though it has been open since Dec 10, 2014)

0reactions
azzcommented, Jun 24, 2017

Actually TypeScript still uses ObjectLiteralExpression instead of ObjectBindingPattern in the following case:

({ foo = [] } = bar);

Prettier currently prints this as

// --parser typescript
({ foo } = bar);
// --parser babylon
({ foo = [] } = bar);
// --parser flow
SyntaxError: Unexpected token = (1:8)
> 1 | ({ foo = [] } = bar);
    |        ^

Babylon is the only one that is correct.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jest doesn't understand flow types and object destructuring?
It seems that there are issues with the method signature using destructuring and flow types at the same time ( BuilderOptionsType object):
Read more >
Flow – JavaScript Type Checker | Object Computing, Inc.
Flow is a static type checker, designed to find type errors in JavaScript ... By default, the values null and undefined are not...
Read more >
Understanding TypeScript Configuration Options
TypeScript searches for the file with .ts , .tsx and .d.ts by default and, if allowJs is set to true, .js and .jsx...
Read more >
Overzealous Destructuring | Aleksandr Hovhannisyan
The first problem with destructuring is that it strips object properties of their namespace, making it harder to tell, at a glance, ...
Read more >
babel/plugin-transform-flow-strip-types
It will also throw errors for any Flow annotations found in files without the directive. allowDeclareFields. boolean , defaults to false. Added in:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found