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 type spread failing on imported type from other module or libdef (e.g. flow-typed)

See original GitHub issue

babel-7 branch - I’m looking into this. found is in a local libdef.

import type {RoutingState} from 'found'

type Props = {
  ...$Exact<RoutingState>,
  classes: Object,
  children?: Element<*>,
  currentUser?: CurrentUser,
  t: Function,
  width: string,
}

appframe_js_-af-__projects_af-_rubymine_2017_2_eap

TypeError: src/App/AppFrame.js: Cannot read property 'key' of undefined
    at /Users/kross/projects/ui/node_modules/@alienfast/babel-plugin-flow-react-proptypes/lib/makePropTypesAst.js:154:19
    at Array.map (native)
    at makeObjectAstForShape (/Users/kross/projects/ui/node_modules/@alienfast/babel-plugin-flow-react-proptypes/lib/makePropTypesAst.js:153:48)
    at makePropTypesAstForPropTypesAssignment (/Users/kross/projects/ui/node_modules/@alienfast/babel-plugin-flow-react-proptypes/lib/makePropTypesAst.js:43:12)
    at annotate (/Users/kross/projects/ui/node_modules/@alienfast/babel-plugin-flow-react-proptypes/lib/index.js:101:85)
    at /Users/kross/projects/ui/node_modules/@alienfast/babel-plugin-flow-react-proptypes/lib/index.js:181:20
    at Array.forEach (native)
    at PluginPass.ClassDeclaration (/Users/kross/projects/ui/node_modules/@alienfast/babel-plugin-flow-react-proptypes/lib/index.js:178:29)
    at newFn (/Users/kross/projects/ui/node_modules/babel-traverse/lib/visitors.js:266:21)
    at NodePath._call (/Users/kross/projects/ui/node_modules/babel-traverse/lib/path/context.js:71:18)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:4
  • Comments:31 (27 by maintainers)

github_iconTop GitHub Comments

2reactions
grrowlcommented, Jan 3, 2018

I believe this fails due to the same root cause:

export type QuerySingle<BaseQuery> = {|
  id: number,
  ...BaseQuery,
|}

in babel-plugin-flow-react-proptypes/lib/convertToPropTypes.js:165, spreadShape.properties.forEach explodes because spreadShape doesn’t have a properties property at all (possibly because it’s of type GenericTypeAnnotation?)

1reaction
brigandcommented, Nov 13, 2019

@TSMMark that might happen if you have a type import (import type ...), since at the point the import is reached, we don’t know whether or not we need it at runtime. The import is modified such that the babel flow plugin won’t strip it, and then we can use it later if you refer to the type in a place that we process.

Read more comments on GitHub >

github_iconTop Results From Across the Web

flowtype coverage report is not picking up types I have already ...
1. Type already covered by flow-typed still not being used (Line #6) · 2. Custom library definition file not be picked up (Line...
Read more >
Object Types - JavaScript. Flow
Exact object types are more precise and interact better with other type system features, like spreads. Object type syntax. Object types try to...
Read more >
Adventures in Static Typing: React, Redux, Flow, Oh My
Use Object annotations, then replace with concrete types. E.g. { uuid: string } or reusable, domain-level types ( Reservation ); Define objects ......
Read more >
Read more - GitHub
This includes the bigint type itself, subtyping with literals, libdefs, ... is present or that import types from other modules that use this...
Read more >
How to incrementally add Flow to an existing React app
Flow [https://flow.org/] is a static type checker for Javascript. ... get ready for using libdefs created using the flow-typed NPM package.
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