mirror of
https://github.com/wassname/talk.git
synced 2026-07-14 11:18:50 +08:00
Use builtin types
This commit is contained in:
@@ -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,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.
|
||||
|
||||
Reference in New Issue
Block a user