Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace custom Diff type with new built-in Exclude type #43

Merged
merged 1 commit into from
Jun 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/sweetalert2-react-content.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,8 @@ interface ReactOptions {
footer?: ReactElementOr<'footer'>;
}

// Diff<> and Owerwrite<> types below are inspired from this GitHub comment:
// https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458

// Diff<T, U> is a subtraction operator for string literal types.
// It returns the string types of T that are not in U.
// ex: Diff<('a' | 'b' | 'c'), ('c' | 'd')>; // 'a' | 'b'
type Diff<T extends string, U extends string> =
({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];

// Overwrite<T, U> will take the properties of U and add to it the properties of T that are not in U.
// This emulates an overwrite (override) of chosen properties of T with properties of U.
// It works like { ...T, ...U } in JS.
type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U;
// https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-393936055
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;