Use builtin types

This commit is contained in:
Chi Vinh Le
2018-07-16 16:25:10 -03:00
parent abfa39529f
commit 524994d139
2 changed files with 3 additions and 11 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
// TODO: (@cvle) Extract useful common types into its own package.
export { Diff, Omit, Overwrite, PropTypesOf } from "talk-ui/types";
export { Omit, Overwrite, PropTypesOf } from "talk-ui/types";
+2 -10
View File
@@ -2,27 +2,19 @@ import React from "react";
// TODO: Extract useful common types into its own package.
/**
* Returns literals types that are in T but not in U.
*
* E.g. Diff<"a" | "b", "a"> = "b"
*/
export type Diff<T extends keyof any, U extends keyof any> = ({ [P in T]: P } &
{ [P in U]: never } & { [x: string]: never; [x: number]: never })[T];
/**
* Overwrite properties of `T`.
*
* E.g. Omit<{a: boolean, b: boolean}, "b"> = {a: boolean}
*/
export type Omit<U, K extends keyof U> = Pick<U, Diff<keyof U, K>>;
export type Omit<U, K extends keyof U> = Pick<U, Exclude<keyof U, K>>;
/**
* Overwrite properties of `T`.
*
* E.g. Overwrite<{a: boolean}, {a: string}> = {a: string}
*/
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U;
export type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
/**
* Returns the PropTypes from a React Component.