I get a type error if I try to use an object literal with a generic type that has a type constraint, I am struggling to figure out why:
type WithKey = {
readonly akey: string;
}
function listOfThings<T extends WithKey>(one: T) {
// This is ok
const result2: Array<T> = [one];
//This errors with Type '{ akey: string; }' is not assignable to type 'T'.
const result: Array<T> = [{ akey: 'foo' }];
return result;
}
const hmm = listOfThings({akey: "foo", bkey: 123});to produce?