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.

Flow cannot access types defined in source code

See original GitHub issue

Description

it looks like there are lots of nice flow typing already inlined for many react native apis/components. but my flow typechecker is not able to access them in my project.

I’m guessing Flow is not able to leverage the existing types in the source, possibly due to this file using getters (flow cant resolve types from getters?) :

https://github.com/facebook/react-native/blob/0.42-stable/Libraries/react-native/react-native.js#L9

Reproduction Steps and Sample Code

Here’s an example that isn’t working:

// @flow
import { StatusBar } from 'react-native';

const fn = () => {
  StatusBar.setBarStyle('this-is-not-in-enum');
};

The call to StatusBar.setBarStyle should generate a flow error based on the flow types in the react-native source code. You can see that code in https://github.com/facebook/react-native/blob/0.42-stable/Libraries/Components/StatusBar/StatusBar.js#L201

My .flowconfig:

[ignore]
; We fork some components by platform
.*/*[.]android.js

; Ignore templates for 'react-native init'
.*/local-cli/templates/.*

; Ignore the website subdir
<PROJECT_ROOT>/website/.*

; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/

; Ignore unexpected extra "@providesModule"
.*/node_modules/.*/node_modules/fbjs/.*

; Ignore duplicate module providers
; For RN Apps installed via npm, "Libraries" folder is inside
; "node_modules/react-native" but in the source repo it is in the root
.*/Libraries/react-native/React.js
.*/Libraries/react-native/ReactNative.js

[include]

[libs]
Libraries/react-native/react-native-interface.js
flow/

[options]
emoji=true

module.system=haste

experimental.strict_type_args=true

munge_underscores=true

module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FixMe

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-8]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-8]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy

unsafe.enable_getters_and_setters=true

[version]
^0.38.0

Additional Information

  • React Native version: 0.42.3
  • Platform: n/a
  • Development Operating System: osx
  • Dev tools: flow 0.38.0

p.s. SO issue here: http://stackoverflow.com/questions/43126131/how-to-use-react-native-flow-types

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
janicduplessiscommented, Mar 31, 2017

This is actually a regression in recent RN versions, we used to do a hack to work around getters not working but they do work now so we removed the hack but didn’t enable flow in react-native-implementations.js which exports all RN modules.

I have a PR up to fix this but it hasn’t been reviewed yet. https://github.com/facebook/react-native/pull/12917

0reactions
hramoscommented, Jul 25, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we’re automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accessing type values on object types · Issue #2865 - GitHub
I've introduced my team to flow and it's mostly going well. We're adding flow to an existing codebase, and there are several situations ......
Read more >
How do I fix this flow < 0.114 error with react-native > 0.64?
I had to create this folder flow-typed in my project then a new file inside it called myLibDef.js and declare declare type symbol...
Read more >
Object Types - JavaScript. Flow
In JavaScript, accessing a property that doesn't exist evaluates to undefined . This is a common source of errors in JavaScript programs, so...
Read more >
What I wish I had known before starting to use Flow
I recently converted the definition of an open source library from Typescript to Flow. I tried to use an automatic converter (flowgen) and ......
Read more >
Flow – JavaScript Type Checker | Object Computing, Inc.
It is an open source tool from Facebook that is implemented using the OCaml ... Node.js cannot directly run code that is annotated...
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