-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Reinterpret a type parameter constrained to any as an upper bound constraint #29571
Reinterpret a type parameter constrained to any as an upper bound constraint #29571
Conversation
@typescript-bot test this |
Heya @RyanCavanaugh, I've started to run the extended test suite on this PR at 570c756. You can monitor the build here. It should now contribute to this PR's status checks. |
Also run on DT |
@typescript-bot run dt |
Heya @weswigham, I've started to run the Definitely Typed test suite on this PR at 7c13b70. You can monitor the build here. It should now contribute to this PR's status checks. |
Updated the test that needed changing to a constraint that actually typechecks, and looked at DT - failures are in So this seems pretty good - if anything, like the tests I just changed, it's going to identify places we were silently allowing unsafe operations. |
@weswigham let's merge for 3.5 |
@weswigham this sounds like it's ready to go, right? |
Probably. The change itself is small, so barring merge conflicts, should still be OK. |
After a merge from master: toString is now available on type parameters that extend any. That's the only difference I can see. |
Let's wait until @RyanCavanaugh is back to merge this. |
I talked to @RyanCavanaugh about this just now, so I'm going to merge it. |
@weswigham this causes a failure in DT on wordpress__block-editor-tests.tsx. Can you try to fix it? It looks like the offending signature is this: declare function withColorContext<
ProvidedProps extends Partial<withColorContext.Props>,
OwnProps extends any,
T extends ComponentType<ProvidedProps & OwnProps>
>(component: T):
T extends ComponentType<infer U> ? ComponentType<
Omit<U, 'colors' | 'disableCustomColors' | 'hasColorsToChoose'> &
Omit<ProvidedProps, 'hasColorsToChoose'>> :
never; Previously the second type argument was inferred If there's a mechanical fix to update existing code, it'd worthwhile to have that in the release notes for 3.9. |
Write an eg, type GetClass<T extends any> = T["class"];
// could be
type GetClass<T> = Extract<T, {class: any}>["class"]; obviously, you can replace
What's broken about it? the signature itself has nothing wrong as far as I can tell, so you're talking about a specific usage, right? |
If the answer is "we now infer |
Yes, line 142 of the tests. Probably |
Fixes #29509
Note, that we have a test that asserts that a type parameter explicitly extending
any
behaves likeany
when accessing its members (which IMO is strange). This would be a break to that behavior.