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

Try using forwardRef #2222

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

johnrom
Copy link
Collaborator

@johnrom johnrom commented Jan 17, 2020

Note: Formik no longer appears maintained, but I am leaving this PR open for archival purposes.

@vercel vercel bot temporarily deployed to Preview January 17, 2020 18:11 Inactive
@vercel
Copy link

vercel bot commented Jan 17, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/jared/formik-docs/pfkqgq5m4
✅ Preview: https://formik-docs-git-fork-johnrom-johnrom-forwardref.jared.now.sh

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 17, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 31d669d:

Sandbox Source
Formik TypeScript Playground Configuration

@vercel vercel bot temporarily deployed to Preview January 17, 2020 18:28 Inactive
@jaredpalmer
Copy link
Owner

Does this work with ts?

@johnrom
Copy link
Collaborator Author

johnrom commented Jan 29, 2020

yes, because but only because there is a cast. I left a comment on #2208 describing the pros and cons. as far as I can tell, it is the best we can do for now.

@jaredpalmer
Copy link
Owner

I'm pretty scared of this since this cast effectively removes type safety for development.

@johnrom
Copy link
Collaborator Author

johnrom commented Jan 29, 2020

The type safety that is removed is specifically the safety between the two type definitions. If those type definitions go out of sync somehow, type safety will not be guaranteed. As long as those type definitions are in sync, type safety is guaranteed. It's definitely a trade-off, but is the only way to implement forwardRef that I can find. I'd recommend raising an issue on either typescript or react libraries. Coming from the owner of a large library, it might have some weight, and maybe one of the gurus would have a better solution. There's a lot of discussion here, but I don't see an issue opened specifically for the forwardRef case. The second best case scenario is ignoring only specific typescript rules.

Alternatively, we could add a comment like // DO NOT CHANGE OR THE UNIVERSE EXPLODES as a reminder that those two type definitions must remain in sync.

@mlzsolti
Copy link

Guys, if this is working, could you please write an example how to use it, as the docs don't seem clear about this? Thank you.

@johnrom
Copy link
Collaborator Author

johnrom commented Feb 14, 2020

@mlzsolti this PR is experimental. Since it uses type casting, it could introduce problems with future maintenance due to types becoming out of sync. It's a gamble I'm not sure Jared is willing to take.

I would give 100% approval to this if we could ignore the specific rule this violates, since it will never be violated.

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

Successfully merging this pull request may close these issues.

3 participants