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

[react] add tests for useState #36338

Merged
merged 1 commit into from Jun 21, 2019

Conversation

joehillen
Copy link
Contributor

Add a test case to prevent this from happening again.

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

Add a test case to prevent this from happening again:

DefinitelyTyped@598ffd0#r34006320
@ferdaber
Copy link
Contributor

So how does this pass here but not in the reported cases?

@typescript-bot typescript-bot added this to Waiting for Reviewers in Pull Request Status Board Jun 21, 2019
@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Awaiting reviewer feedback labels Jun 21, 2019
@typescript-bot
Copy link
Contributor

typescript-bot commented Jun 21, 2019

@joehillen Thank you for submitting this PR!

🔔 @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @DovydasNavickas @onigoetz @theruther4d @guilhermehubner @ferdaber @jrakotoharisoa @pascaloliv @Hotell @franklixuefei @Jessidhia @saranshkataria @lukyth @eps1lon - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@joehillen
Copy link
Contributor Author

@ferdaber Correct. Here is the test output if I revert your revert:

Error: /home/joe/src/DefinitelyTyped/types/react/test/hooks.tsx:217:15
ERROR: 217:15  expect  TypeScript@next compile error: 
Parameter 'r' implicitly has an 'any' type.
ERROR: 217:15  expect  TypeScript@next compile error: 
Argument of type '(r: any) => boolean' is not assignable to parameter of type 'boolean | ((prevState: false) => false) | ((prevState: true) => true)'.
  Type '(r: any) => boolean' is not assignable to type '(prevState: false) => false'.
    Type 'boolean' is not assignable to type 'false'.

    at /home/joe/src/DefinitelyTyped/node_modules/dtslint/bin/index.js:190:19
    at Generator.next (<anonymous>)
    at fulfilled (/home/joe/src/DefinitelyTyped/node_modules/dtslint/bin/index.js:5:58)
    at <anonymous>
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@typescript-bot
Copy link
Contributor

👋 Hi there! I’ve run some quick performance metrics against master and your PR. This is still an experiment, so don’t panic if I say something crazy! I’m still learning how to interpret these metrics.

Let’s review the numbers, shall we?

Comparison details 📊
master #36338 diff
Batch compilation
Type count 53266 53298 +0.1%
Assignability cache size 23771 23799 +0.1%
Subtype cache size 3886 3889 +0.1%
Identity cache size 764 765 +0.1%
Language service
Samples taken 8788 2109 -76.0%
Identifiers in tests 2524 2532 +0.3%
getCompletionsAtPosition
    Mean duration (ms) 401.8 376.3 -6.4%
    Median duration (ms) 383.4 367.7 -4.1%
    Mean CV 11.1%
    Worst duration (ms) 853.0 839.8 -1.5%
    Worst identifier TransitionGroup TransitionGroup
getQuickInfoAtPosition
    Mean duration (ms) 414.2 388.5 -6.2%
    Median duration (ms) 401.5 380.8 -5.2%
    Mean CV 11.9%
    Worst duration (ms) 836.9 773.3 -7.6%
    Worst identifier component component
System information
Node version v10.15.3 v10.15.3
CPU count 2 2
CPU speed 2.294 GHz 2.294 GHz
CPU model Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz
CPU Architecture x64 x64
Memory 6.8 GiB 6.8 GiB
Platform linux linux
Release 4.15.0-1041-azure 4.15.0-1045-azure

It looks like nothing changed too much. I’m pretty lenient since I’m still an experiment, so take a look anyways and make sure nothing looks out of place.


If you have any questions or comments about me, you can ping @andrewbranch. Have a nice day!

@DanielRosenwasser
Copy link
Member

Is it effectively just a difference between versions? (CC @weswigham)

@joehillen
Copy link
Contributor Author

joehillen commented Jun 21, 2019 via email

@joehillen
Copy link
Contributor Author

To clarify, this test case is a common pattern in my React codebase and is what started returning an error when I updated @types/react and TS 3.5 yesterday. I suspect the error has to do with both the bad commit and the smarter type unions change introduced in 3.5.

What I think happened is (prevState: boolean) => boolean was widened to ((prevState: false) => false) | ((prevState: true) => true), which doesn't make sense because why would you ever call setState but not change the value.

Because it is such a common pattern in React, I thought it made an obvious test case.

@weswigham weswigham merged commit 79e2481 into DefinitelyTyped:master Jun 21, 2019
Pull Request Status Board automation moved this from Waiting for Reviewers to Done Jun 21, 2019
@joehillen joehillen deleted the useState-tests branch June 22, 2019 00:58
iRON5 pushed a commit to iRON5/DefinitelyTyped that referenced this pull request Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Popular package This PR affects a popular package (as counted by NPM download counts).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants