3 ms·
It couldn’t, no: the object being frozen might contain more attributes than its type describes. Typescript can’t know these extra attributes.
by williamdclt 3y ago
It couldn’t, no: the object being frozen might contain more attributes than its type describes. Typescript can’t know these extra attributes.
- gavinray 3y agoAt the very least, it could return an intersection type that is equivalent to the known keys in the object so you get autocomplete, but allow other arbitrary properties of unknown type: type FrozenObject<T> = { readonly [K in keyof T]: T[K] } & { readonly [key: string]: unknown }; const x = { foo: 1, bar: "hello" } x["baz"] = "blah" const frozen = Object.freeze(x) as FrozenObject<typeof x> const baz = frozen.baz // No autocomplete for 'baz', but no error either