Skip to content

Instantly share code, notes, and snippets.

View dlaub3's full-sized avatar
:shipit:

Daniel Laubacher dlaub3

:shipit:
View GitHub Profile
@dlaub3
dlaub3 / tsconfig.json
Created November 26, 2021 11:11
tsconfig-codesandbox-react
{
"compilerOptions": {
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
@dlaub3
dlaub3 / ts
Last active February 11, 2023 16:58
TS Utilities
// Extract the desired values from a union of objects
type ExtractUnionValues<T extends {}, ExcludProps extends string = never> = T extends Extract<T, { [K in infer P]: any }> ? T[Exclude<P, ExcludProps>] : never
type PickUnionValues<T extends {}, Props extends string = never> = T extends Extract<T, { [K in infer P]: any }> ? T[Extract<P, Props>] : never
// alternative implementation
type ExtractUnionValues<T extends {}, ExcludedProps extends string = never> = T extends {} ? Omit<T, ExcludedProps>[keyof Omit<T, ExcludedProps>]: never
type PickUnionValues<T extends {}, Props extends string = never> = T extends {} ? Pick<T, Extract<keyof T, Props>>[keyof Pick<T, Extract<keyof T, Props>>]: never