Check out this code snippet:
export type Types = 'a' | 'b';
export type MyPartials = {
readonly [P in keyof Types]?: number;
};
export interface MyI {
readonly name: string;
readonly myPartials: MyPartials;
}
export const myIs = [
{
name: 'A',
myPartials: {a: 5},
},
{
name: 'B',
myPartials: {},
},
{
name: 'C',
myPartials: {},
},
] as const;
const typeCheck = (arr: readonly MyI[]): void => {};
typeCheck(myIs); //error on arg
Play with the code here. This code is generating an error that I can't seem to figure out, primarily because it's overly verbose. The goal here is to ensure that each element in the array is of type MyI
. Why am I unable to pass this into a function that expects an array of MyI
?