I am setting up an abstraction for a database repository pattern. My ProductRepository class takes a single generic type parameter, which is constrained using the Product interface to ensure that the type contains an id: number field. I then define functions and arguments of my database accessor based on a generic type parameter passed into my DB type.
However, the constraint does not seem to be taken into account when I attempt to call the findFirst function of my DB type, and I get the error:
Type '{ id: number; }' is not assignable to type 'Partial<T>'
Despite the fact that my generic T should be constrained to the Product interface, which does contain an id, and so I would expect that the object { id } matches the type Partial<T extends Product>. Typescript gives me no further information about why the types do not match.
Interestingly, if I instead pass Product directly as the type parameter (instead of T), this error goes away (but I get other errors). For context, there is no Product table in my database, but this is instead an abstraction for functionality that many tables will share.
The minimal code block is in a comment following this one (as well as a link to a replication in typescript playground).