Created
April 26, 2018 14:03
-
-
Save ulve/e2e24f455fa3406a928ba4e7b2aed3f7 to your computer and use it in GitHub Desktop.
Keys of types that differ from a base type
This file contains 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
interface IBase { | |
nånProp: string; | |
} | |
interface IFirst extends IBase { | |
fulProp: string; | |
} | |
interface ISecond extends IBase { | |
FulProp: string; | |
} | |
type TypeDiff<T extends string, U extends string> = ({ [P in T]: P } & | |
{ [P in U]: never } & { [x: string]: never })[T]; | |
type TypeOmit<T, K extends keyof T> = Pick<T, TypeDiff<keyof T, K>>; | |
type propName = keyof TypeOmit<IFirst & ISecond, keyof IBase>; | |
var p: propName = "fulProp"; | |
const värde: IFirst | ISecond = { | |
nånProp: "katt", | |
[p]: "hund" | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment