-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
[typescript] Fix conflicting types for onChange prop #8618
[typescript] Fix conflicting types for onChange prop #8618
Conversation
@@ -46,7 +46,7 @@ export interface Color { | |||
*/ | |||
export type Diff<T extends string, U extends string> = ({ [P in T]: P } & | |||
{ [P in U]: never } & { [x: string]: never })[T]; | |||
export type Omit<T, K extends keyof T> = { [P in Diff<keyof T, K>]: T[P] }; | |||
export type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the more correct typing; it makes it unnecessary to wrap Omit
in Partial
everywhere it's used. I went ahead and made that change as part of this PR.
f9194b3
to
3ccaa41
Compare
Should we add some tests for this PR? |
@oliviertassinari I think the best way to test this is turn on |
When I turn on const GridListTest = () =>
<GridList cellHeight={160} cols={3}>
<GridListTest cols={1}>
<img src="img.png" alt="alt text" />
</GridListTest>,
</GridList>; This seems like a bug; |
test/typescript/components.spec.tsx
Outdated
<img src="img.png" alt="alt text" /> | ||
</GridListTest>, | ||
</GridList>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turning on noImplicitAny
caught this bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GridListTile
instead
|
||
export type BottomNavigationProps = { | ||
children: React.ReactNode; | ||
onChange?: (event: React.ChangeEvent<{}>, value: any) => void; | ||
showLabels?: boolean; | ||
value?: any; | ||
} & React.HTMLAttributes<HTMLDivElement>; | ||
} & Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and fixed this one too.
@@ -1,12 +1,13 @@ | |||
import * as React from 'react'; | |||
import { StyledComponent } from '..'; | |||
import { Omit } from '../index'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you merge this with the above import.
@oliviertassinari did you mean to remove the |
@pelotom I have deleted the v1 tag. Instead, I'm using the |
* Fix conflicting types for TextField.onChange (resolves mui#8617) * Get rid of Partial made unnecessary by better definition of Omit * Enable noImplicitAny to test that event handlers infer correct type * Test that BottomNavigation.onChange has correct type * Use GridListTile * Merge named imports
Resolves #8617