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(react-router): Failing with strictFunctionTypes #38453
fix(react-router): Failing with strictFunctionTypes #38453
Conversation
@eps1lon Thank you for submitting this PR! 🔔 @sergey-buturlakin @mrk21 @vasek17 @ngbrown @awendland @KostyaEsmukov @johnnyreilly @LKay @DovydasNavickas @huy-nguyen @Grmiade @DaIgeb @egorshulga @rraina @pret-a-porter @t49tran @8enSmith @wezleytsai @HipsterBrown - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
Since you're a listed owner and the build passed, this PR is fast-tracked. A maintainer will merge shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
If we merge this can we make sure we re-open or re-file #38271 so it's not lost? |
Yes. I probably have another fix for this and suspect it's actually an issue with TypeScript. I'll narrow it down a bit more and keep you posted (likely pinging you in a TS issue). |
1a03f8f
to
69cd1a3
Compare
Shouldn't we add another test to prevent future regressions? const Component = withRouter(({ a, b, location, ...props }: ComponentOwnProps & RouteComponentProps) => {
// ...
}); |
Thanks for opening microsoft/TypeScript#33490 |
👋 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 📊
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 |
I'll check it out later. I think main issue that caused this regression was that the tests do not run with |
|
The default for |
I would have expected the opposite: strict types work with loose settings, while loose types will break with strict settings. |
👍 looks good to me, we should get this fix in. I think it might be worth moving to have |
I just published |
I need to revisit how we implemented the type helper I have in mind but one issue with |
Resolves issues reported in #38271 (comment) and #38326 (comment)
I'll try to make sense of the current issue later in this text but TL;DR: The introduced bug reports have more upvotes than the fixed bug reports so we revert until we figure out what's happening.
I tried to fiddle around with the
withRouter
declaration but anything I tried created an error in a different version of TS with strictFunctionTypes.The current issue is a result of
C & ComponentType<P>
which resolves (in the removed test case) toFunctionComponent<P> | (Functioncomponent<P> & ComponentClass<P>)
which is probably a result of the intermediate distribution of&
to(FunctionComponent<P> & FunctionComponent<P>) | (FunctionComponent<P> & ComponentClass<P>) | (ComponentClass<P> & FunctionComponent<P>) | (FunctionComponent<P> & ComponentClass<P>)
which should be simplified toFunctionComponent<P> | ComponentClass<P> | (FunctionComponent<P> | ComponentClass<P>)
but for some reason theComponentClass<P>
is dropped. Maybe TypeScript is using only the first part of the union and resolves theC
inC & ComponentType<P>
toFunctionComponent<P> & ComponentType<P>
which would explain the result.