Trying to solve the problem with possible to pass not all needed keys for create class instance, mentioned by @jcals, I think I need custom class which constructor takes only object of corresponds keys, value type:
function getEntries<
T extends Record<PropertyKey, unknown>,
K extends keyof T,
V extends T[K]>(o: T) {
return Object.entries(o) as [K, V][]
}
interface T_Dict<K extends PropertyKey, V> extends ReadonlyMap<K, V> {get(key: K): V}
export class DictObject<K extends PropertyKey, V> extends Map<K, V> implements T_Dict<K, V>{
constructor(obj: Record<K, V>) {
super(getEntries(obj))
}
public override get(key: K): V {
if (!this.has(key)) throw new Error('Wrong key!')
return this.get(key)
}
}
But I cant force it to produce instanse of ReaadOnlyMap - it's still has method like delete/clear (