Рассмотрим эту настройку.
interface C {
foo: string
}
interface A {
B: Record<string, C>
// ... some more properties
}
const test: A = {
B: { hi: {foo: "hello"} }
// ... some more properties
}
Теперь я хочу иметь возможность
test.B.toArray()
, что будет делать
Object.values(test.B)
Теперь вот частичное решение Я придумал, что меня не устраивает.
interface C {
foo: string;
}
interface A {
B: { value: Record<string, C>; toArray: () => Array<C> };
}
const test: A = {
B: {
value: { hi: { foo: "hello" } },
toArray: function (): Array<C> {
return Object.values(this.value);
},
},
};
//Why I am not happy with this solution is I now have to refer to
test.B
// as
test.B.value