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.

Problem with Flow typing of withI18nProps: suppressed errors

See original GitHub issue

I have come across an unusual problem when using js-lingui’s Flow types. Creating an intersection type between a regular component props object and withI18nProps type leaves Flow unable to detect errors when using this props object.

I have created a minimal reproduction case here, but briefly an example can be recreated like this:

  • declare a component Props type with arbitrary fields, e.g.:
type Props = {|
  foo: string
|};
  • import withI18nProps type from @lingui/react

  • intersect the Props type with the withI18nProps type:

type Props = {|
  foo: string
|}  & withI18nProps;

or, alternatively, spread the withI18nProps type in the Props object type:

type Props = {|
  foo: string,
  ...withI18nProps
|};
  • in the React component, try to access a property not declared in the Props type (e.g. this.props.x)

  • notice that Flow is not marking this as an error

  • remove withI18nProps from the intersection (or from the object where it was spread) and notice that Flow now catches the error of accessing the non-declared property.

I could not replicate the problem as a cleaner and smaller case in try Flow, but I hope the provided info will be enough to help you find the problem.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tricoder42commented, Aug 9, 2018

Flow types are included in npm packages since release 2.4.0

1reaction
tricoder42commented, Jul 26, 2018

@azangru I see! Thanks. I’ve created a new issue (#250) to fix this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Suppressions - JavaScript. Flow
How to suppress Flow errors. ... This code concisely describes the type of issue the error is reporting, and is different between different...
Read more >
Suppress an Error in Flow - Medium
If you are using Flow to provide static type checking in your JavaScript, you can suppress a flow error message on a one-off...
Read more >
Configure Flow to ignore "Missing type annotation for ..." errors ...
I would like to configure flow to ignore that kind of errors for now. I will add types to everything later on, and...
Read more >
Flow best practices - Notes about software engineering
For example, one has changed the type of the arguments, ... If the project has sufficient flow coverage, logs of flow errors will...
Read more >
Flow - JavaScript Static Type Checker - byby.dev
If you are confident your code is correct, and that Flow is erroring too conservatively, you can suppress the error so that Flow...
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