Skip to content
New issue

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

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

Already on GitHub? # to your account

Extract<Type, Union> #9

Open
nmsn opened this issue Dec 6, 2022 · 1 comment
Open

Extract<Type, Union> #9

nmsn opened this issue Dec 6, 2022 · 1 comment

Comments

@nmsn
Copy link
Contributor

nmsn commented Dec 6, 2022

Constructs a type by extracting from Type all union members that are assignable to Union.

type T0 = Extract<"a" | "b" | "c", "a" | "f">;
// type T0 = "a"

type T1 = Extract<string | number | (() => void), Function>;
// type T1 = () => void
@nmsn
Copy link
Contributor Author

nmsn commented Dec 6, 2022

/**
 * Extract from T those types that are assignable to U
 */
type Extract<T, U> = T extends U ? T : never;

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant