Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

typescript type only the object value

const satisfies = <T,>() => <U extends T>(u: U) => u;

const mapper1 = satisfies<Record<string, Type1>>()({ foo1: bar1, foo2: bar2 });
const mapper2 = satisfies<Record<string, Type2>>()({ foo3: bar3, foo4: bar4 });
export type MapperKeys = keyof typeof mapper1 | keyof typeof mapper2;
// type MapperKeys = "foo1" | "foo2" | "foo3" | "foo4"
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #typescript #type #object
ADD COMMENT
Topic
Name
1+5 =