Is there a way to dereference an optional field from an interface in the following scenario?
interface Sample {
key1?: Array<Obj1>
}
interface Obj1 {
a?: Obj2;
}
interface Obj2 {
b?: string;
}
const a: Sample["key1"][number]["a"]["b"] = "asd";
Whenever I try this, I encounter an error at Sample["key1"][number]
with the message
Type 'Obj1[] | undefined' has no matching index signature for type 'number'.
Any insights on how to overcome this obstacle would be greatly appreciated!