Picture a straightforward CollectionStore
that contains methods for creating and updating a record. The create()
method takes in a set of attributes and returns the same set with an added id
property. On the other hand, the update
method requires the set to have an already defined id
property.
In Typescript, how can I indicate that the create()
function accepts a type T
and returns T & {id: string}
?
The expected pattern might look something like this:
interface CollectionStore<T> {
updateRecord(T & {id: string}): void;
createRecord(T): T & {id: string};
}
However, the above code snippet is not valid. Assistance would be greatly appreciated! =)