I encountered the following error message
[ts] Type '{ type: string; }' is not assignable to type 'A'.
when using this code snippet
interface Action {
type: string;
}
function requestEntities<A extends Action>(type: string) {
return function (): A {
return { type };
};
}
Why can't it be assigned? A
is defined as extending Action
, which contains only one property: type
, of type string. What could be causing this issue?
Could the problem stem from the possibility that A
might have additional properties? If so, how can I specify in TypeScript that A
should still only contain the property type: string
and nothing else?
UPDATE
Just to clarify, the reason for introducing the generic A
is because A
will specifically have a string value assigned to the type
property, such as { string: 'FETCH_ITEMS' }
.