4 ms·
At 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 pr
by gavinray 3y ago
At 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