Skip to content

Instantly share code, notes, and snippets.

@ulve
Created April 26, 2018 14:03
Show Gist options
  • Save ulve/e2e24f455fa3406a928ba4e7b2aed3f7 to your computer and use it in GitHub Desktop.
Save ulve/e2e24f455fa3406a928ba4e7b2aed3f7 to your computer and use it in GitHub Desktop.
Keys of types that differ from a base type
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