react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

[react-stately][useControlledState] Allow undefined params

Open ChocolateLoverRaj opened this issue 3 years ago • 6 comments

Closes #1859

✅ Pull Request Checklist:

  • [x] Included link to corresponding React Spectrum GitHub Issue.
  • [ ] ~~Added/updated unit tests and storybook for this change (for new code or code which already has tests).~~ (No existing way of checking types found, so I couldn't test this.)
  • [x] Filled out test instructions.
  • [x] Updated documentation (if it already exists for this component).
  • [x] Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Try doing useControlledState(undefined, undefined, undefined) in typescript with strictNullChecks compiler option turned on. There should not be any TypeScript errors.

🧢 Your Project:

https://github.com/ChocolateLoverRaj/color-picker

ChocolateLoverRaj avatar May 10 '21 21:05 ChocolateLoverRaj

Signed Adobe CLA

ChocolateLoverRaj avatar May 10 '21 21:05 ChocolateLoverRaj

Not sure about this - see my question https://github.com/adobe/react-spectrum/issues/1890#issuecomment-841550833

dannify avatar May 25 '21 00:05 dannify

Not sure about this - see my question #1890 (comment)

@dannify This pull request fixes #1859, which fixes strictNullChecks errors on packages using @react-stately/utils. This pull request doesn't require the strictNullChecks compiler to be turned on for this package, which is what #1890 is about. This PR only adds 3 | undefineds to the code.

ChocolateLoverRaj avatar May 27 '21 21:05 ChocolateLoverRaj

Yes but as you said, it only solves it for one package and would be introducing the method for solving this problem across all of our packages (even if we did it incrementally) so I want to look at alternative ways to solve the problem as a whole.

dannify avatar Jun 15 '21 19:06 dannify

@danify while it may be hard to solve this problem for all packages, for now you are making it inconvenient for people who do use strictNullChecks.

ChocolateLoverRaj avatar Jun 16 '21 00:06 ChocolateLoverRaj

Correct me if I'm wrong but without this fix you can't really use this utility as intended in a TS codebase with strict or structNullChecks set to true? Was really looking forward to a clever drop-in solution. Fixing the types for this utility so that they are strictly correct doesn't mean any of the other packages that depend on this utility also need to opt in to strict mode. Just that projects that do opt-in can use the utility without workarounds.

angusd3v avatar Mar 07 '22 08:03 angusd3v

please merge this

alisajadih avatar Jan 14 '23 08:01 alisajadih

I turned on our strict type checking for this file, I believe this PR to be wrong. I've opened a PR to address it here https://github.com/adobe/react-spectrum/pull/3926

snowystinger avatar Jan 18 '23 00:01 snowystinger