Hi, I'm trying to write such a code:
export type OptionValue = string | boolean | number | (string | null)
export class Option<T> {
value: T
constructor(value:T) {
this.value = value
}
}
interface GroupLike {
options?: Record<string, Option<OptionValue>>
}
class Group<Options extends Record<string, Option<OptionValue>>> {
options: Options
constructor(cfg: { options: Options}) {
this.options = cfg.options
}
merge<Options2 extends Record<string, Option<OptionValue>>>(
other: Group<Options2>
) {
if (other.options != null) {
for (const [name, option] of Object.entries(other.options)) {
const existingOption = this.options[name]
this.options[name] = option
}
}
//
}
}
But TS tells me that options[name] = option is invalid, as options cant be indexed with string. What's interesting, the previous line works : const existingOption = this.options[name]. Would anyone be so nice and help me figure it out, please? ๐