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

fix: flow typing of React API with Flow 0.92 #448

Merged
merged 1 commit into from
Feb 5, 2019

Conversation

4ian
Copy link
Contributor

@4ian 4ian commented Feb 2, 2019

Nice library! ;) Very well done :D

I've run into a few flow errors when trying to add it on my project (https://github.com/4ian/GDevelop) with Flow 0.92.
I've made a few fixes, hope they are ok.

Changes

  • I'm not sure about LinguiPublisher, I think it should be named createLinguiPublisher or makeLinguiPublisher as it's returning an object rather than being a constructor (i.e: it's not modifying this). I've changed the name and changed its usage to remove the new.
    • I've not seen any reference to LinguiPublisher when googling it. If you think this is breaking the API, we can go back to have it being named LinguiPublisher and have the type named LinguiPublisherType.
  • A test case is there to ensure update of LinguiPublisher can be called without any arguments. But the typing was incorrect then. I've named the parameter (param, not very original) and checked for its existence before destructuring it.
  • A few || null to ensure you're not returning undefined in renders.

Test plan

  • Ran yarn lint and got in pseudoLocalize.test.js:
  38:22  error  Replace "{count,·plural,·one·{{countString}·book}·other·{{countString}·books}}" with ⏎········"{count,·plural,·one·{{countString}·book}·other·{{countString}·books}}"⏎······  prettier/prettier
  39:15  error  Replace "{count,·plural,·one·{{countString}·ƀōōķ}·other·{{countString}·ƀōōķś}}" with ⏎······"{count,·plural,·one·{{countString}·ƀōōķ}·other·{{countString}·ƀōōķś}}"⏎····      prettier/prettier

✖ 2 problems (2 errors, 0 warnings)
  2 errors and 0 warnings potentially fixable with the --fix option.

but this seems to be unrelated to my changes?

  • yarn flow is still passing.
  • flow (with flow version 0.92.0) is down from 5 errors to 2, that are in packages/cli/src/api/compile.js (line 142 and 144):
Cannot call pseudoLocalize with translation bound to message because MessageType [1] is incompatible with string [2].

I've not fixed them because my goal was to get the React API without flow errors :) Original errors where (when using js-lingui in a React project):
image

Also if you feel more comfortable fixing yourself the issues with Flow 0.92 rather than merging/asking changes on this PR, feel free to steal my fixes :)

@4ian
Copy link
Contributor Author

4ian commented Feb 2, 2019

(Failing tests seems due to a memory error - transient issue?)

@tricoder42 tricoder42 merged commit 684bd70 into lingui:master Feb 5, 2019
@tricoder42
Copy link
Contributor

Hey @4ian, thanks! Yeah, you made good points! The CI is broken since Node.js 10.something when mock-fs stopped to work :/ I didn't have enough time to fix this as I'm working on v3...

@4ian
Copy link
Contributor Author

4ian commented Feb 5, 2019

No worries, and thanks for your work on this! Look forward to see v3 😃

@4ian 4ian deleted the fix/flow-react-api branch February 5, 2019 09:54
@tricoder42
Copy link
Contributor

Released in 2.7.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants