Is it possible to create a type constraint such that a type contains non optional keys of an object but not all keys? For example:
class Foo {
key1: number
key2: Object
key3: <other type>
}
const X = {
key1: 'foo'
key2: 'bar'
foo: // compilation error
}
So in this model X
has a subset of keys of Foo
, and compile time checks against non existing keys. Basically Partial<Foo>
but unlike Partial<Foo>
I want it such that if someone references X.key3
it will fail to compile because key3
is not defined on X. Is this possible?