I'm attempting to make this specific example function similar to this one:
interface Foo {
a: number;
b: string;
c: boolean;
}
type Explode<T> = keyof T extends infer K
? K extends unknown
? { [I in keyof T]: I extends K ? T[I] : never }
: never
: never;
type Test = Explode<Foo>;
const test: Test = {a: 1};
This results in the error:
Type '{ a: number; }' is not assignable to type '{ a: number; b: never; c: never; } | { a: never; b: string; c: never; } | { a: never; b: never; c: boolean; }'.
Type '{ a: number; }' is missing the following properties from type '{ a: number; b: never; c: never; }': b, c
Is there a way to create an object of type Test
without encountering the error? I am looking for a type that can accommodate either the field a
, b
, or c
(or be an empty object {}
).