Consider a type:
interface Base {
a: number;
b: number;
c: number;
}
Now consider a type derived from it where c
is not present: Omit<T, "c">
:
type MyType<T> = Omit<T, "c">;
Now consider that I need to browse through the keys of A
and do stuff:
const value: MyType<Base> = {
a: 34,
b: 67,
};
for (const k in value) {
const el = value[k]; // Error
}
An error is raised:
const value: Pick<Base, "a" | "b">
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Pick<Base, "a" | "b">'.
No index signature with a parameter of type 'string' was found on type 'Pick<Base, "a" | "b">'.ts(7053)
What is the best practice here?