Last active
December 26, 2017 16:49
-
-
Save besrabasant/45b313d9b67fff1af201576b08ae281b to your computer and use it in GitHub Desktop.
Ignore extended Props from Parent Interface in Typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type StringLiteralDiff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]; | |
type Omit<T, K extends keyof T> = Pick<T, StringLiteralDiff<keyof T, K>>; | |
interface ComponentProps { | |
propA: string | |
propB: number | |
propC: () => void | |
} | |
interface ExtendedComponentProps extends Omit<ComponentProps, 'propC'> { | |
// only 'propA' and 'propB' are included here. | |
} | |
class SampleComponent extends React.Component<ExtendedComponentProps,{}> { | |
render() { | |
return ( | |
... | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment