The code snippet below demonstrates the similarities and differences between the functions addThingExample2
and addThing
. While addThingExample2
directly uses the union type Things
, addThing
utilizes a generic parameter THING extends Thing
.
The expression
PropsMapper<Things>[TYPE]['id']
is valid and does not produce any type errors.
In contrast,
PropsMapper<THING>[TYPE]['id']
generates a type error stating that "Type '"id"' cannot be used to index type 'PropsMapper<THING>[TYPE]'.
"
I am seeking a solution to enable the compilation of the addThing
function without encountering any type errors.
type AllowedThingType = 'Smartphone' | 'Toy' | 'Magazine';
// Rest of the code goes here...