So I have Array of generic object and want to iterate over the but typescript wont allow me. Here is some sample code. Any Suggestions of how this can be solved.
type someGeneric<T> = { item: T };
type stringGeneric = someGeneric<string>;
type numberGeneric = someGeneric<number>;
type someFunction = <T>(generic: someGeneric<T>) => T;
const someFunction: someFunction = (generic) => generic.item;
const stringGeneric: stringGeneric = { item: 'some String' },
numberGeneric: numberGeneric = { item: 12 };
let genericArray = [stringGeneric, numberGeneric];
genericArray.forEach(generic => {
someFunction(generic); // Error On This line.
});
You can just copy-paste the code to this link. I cant seem to share the code.