Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flow] Define Flow types for style and stylesheet objects, more checking #8882

Closed
wants to merge 1 commit into from

Conversation

ide
Copy link
Contributor

@ide ide commented Jul 19, 2016

  • Define a Styles type for the object that gets passed into StyleSheet.create
  • Define a StyleSheet type that is returned from StyleSheet.create
  • Clean up the type declarations in StyleSheet.create

Test Plan: flow

@ghost
Copy link

ghost commented Jul 19, 2016

By analyzing the blame information on this pull request, we identified @sahrens and @prometheansacrifice to be potential reviewers.

@ghost ghost added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jul 19, 2016
@ide
Copy link
Contributor Author

ide commented Jul 19, 2016

cc @vjeux @brentvatne

@vjeux
Copy link
Contributor

vjeux commented Jul 19, 2016

@yungsters can you take a look?

@vjeux
Copy link
Contributor

vjeux commented Jul 19, 2016

Oh this is actually not adding any new strictness, I can just ship it, thanks

@vjeux
Copy link
Contributor

vjeux commented Jul 19, 2016

@facebook-github-bot shipit

@ghost ghost added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Jul 19, 2016
@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to Phabricator to review internal test results.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 19, 2016
@vjeux
Copy link
Contributor

vjeux commented Jul 19, 2016

Can you rebase?

- Define a Styles type for the object that gets passed into StyleSheet.create
- Define a StyleSheet type that is returned from StyleSheet.create
- Clean up the type declarations in StyleSheet.create

Test Plan: `flow`
@ide ide force-pushed the flow-with-stylesheet-create branch from 276ece9 to 23d77dd Compare July 19, 2016 21:52
@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 19, 2016
@ghost
Copy link

ghost commented Jul 20, 2016

I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification.

@ghost ghost added Import Failed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. and removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Jul 20, 2016
@satya164
Copy link
Contributor

@facebook-github-bot shipit

@@ -17,6 +17,9 @@ var StyleSheetValidation = require('StyleSheetValidation');

var flatten = require('flattenStyle');

export type Styles = {[key: string]: Object};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be {[key: string]: {[key: string]: any} } right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't {[key: string]: any} the same as Object?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ide Not exactly sure how Flow works here. Do arrays also count as objects? If not then they are same :)

Copy link
Contributor Author

@ide ide Jul 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep they are different:

screenshot 2016-07-20 12 07 32

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ide Cool then

@ghost ghost added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Jul 20, 2016
@ghost
Copy link

ghost commented Jul 20, 2016

Thanks for importing. If you are an FB employee go to Phabricator to review internal test results.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 20, 2016
@vjeux
Copy link
Contributor

vjeux commented Jul 20, 2016

It finds some more internal bad code. Someone needs to fix them internally first.

@ghost ghost added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jul 20, 2016
@ghost
Copy link

ghost commented Jul 20, 2016

I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification.

@ghost ghost added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. and removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Jul 20, 2016
@javache
Copy link
Member

javache commented Aug 4, 2016

For some reason, internally this is failing with

react-native-github/Libraries/StyleSheet/StyleSheet.js:20
 20: export type Styles = {[key: string]: Object};
                                          ^^^^^^ object type. This type is incompatible with
 21: export type StyleSheet<S: Styles> = {[key: $Keys<S>]: number};
                                                           ^^^^^^ number

react-native-github/Libraries/StyleSheet/StyleSheet.js:21
 21: export type StyleSheet<S: Styles> = {[key: $Keys<S>]: number};
                                                           ^^^^^^ number. This type is incompatible with
 20: export type Styles = {[key: string]: Object};
                                          ^^^^^^ object type


Found 2 errors

@ide
Copy link
Contributor Author

ide commented Aug 12, 2016

That error doesn't make sense to me, reading the code and running flow (v0.30) myself. Perhaps a different version of Flow? Will try again.

@facebook-github-bot shipit

@ghost
Copy link

ghost commented Aug 12, 2016

I will not rubber stamp and land your change for you @ide! I can import it for you and you can get your change reviewed by someone though :)

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 12, 2016
@vjeux
Copy link
Contributor

vjeux commented Aug 12, 2016

@facebook-github-bot shipit

@ghost ghost added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Aug 12, 2016
@ghost
Copy link

ghost commented Aug 12, 2016

Thanks for importing.If you are an FB employee go to Phabricator to review internal test results.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 12, 2016
@ghost
Copy link

ghost commented Aug 12, 2016

I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification.

@ghost ghost added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. and removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Aug 12, 2016
@gabelevi
Copy link
Contributor

It's possible that improving the types like this exposes mistakes in user code. If you need help I can assist in the merge on Monday

@gabelevi
Copy link
Contributor

Ok, fixed this up and landing it!

The flow error wasn't occurring within the react-native code, but rather in some code that uses react-native. Specifically, it was a jest mock that mocked StyleSheet.create() with an incorrect type. The error message was unfortunate in that it didn't point out the location of the mistake until you ran flow check --traces 10

@ghost ghost closed this in 8eed600 Aug 15, 2016
@ide ide deleted the flow-with-stylesheet-create branch August 15, 2016 18:34
@ide
Copy link
Contributor Author

ide commented Aug 15, 2016

@gabelevi thanks so much for looking into the issue and merging this =)

LearningDave pushed a commit to LearningDave/react-native that referenced this pull request Aug 16, 2016
Summary:
- Define a Styles type for the object that gets passed into StyleSheet.create
- Define a StyleSheet type that is returned from StyleSheet.create
- Clean up the type declarations in StyleSheet.create
Closes facebook#8882

Differential Revision: D3587964

Pulled By: gabelevi

fbshipit-source-id: 629e0176484436848be69b1417638e1200a3669a
mpretty-cyro pushed a commit to HomePass/react-native that referenced this pull request Aug 25, 2016
Summary:
- Define a Styles type for the object that gets passed into StyleSheet.create
- Define a StyleSheet type that is returned from StyleSheet.create
- Clean up the type declarations in StyleSheet.create
Closes facebook#8882

Differential Revision: D3587964

Pulled By: gabelevi

fbshipit-source-id: 629e0176484436848be69b1417638e1200a3669a
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants