Skip to content

Instantly share code, notes, and snippets.

@besrabasant
Last active December 26, 2017 16:49
Show Gist options
  • Save besrabasant/45b313d9b67fff1af201576b08ae281b to your computer and use it in GitHub Desktop.
Save besrabasant/45b313d9b67fff1af201576b08ae281b to your computer and use it in GitHub Desktop.
Ignore extended Props from Parent Interface in Typescript
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