I am trying to create an object where I would like to enforce the keys, but am happy to let typescript deduce the types of the values. A quick example is
const fooVals = {
a: null,
b: null,
c: null,
e: null,
}
type TfooVals = typeof fooVals
type JustKeysOfFooVals = { [key in keyof TfooVals]: any};
// TS deduces correct types of foo1Vals but does not let me know e is missing
const foo1Vals = {
a: 'string',
b: 10,
c: Promise.resolve('string') ,
// e: () => { console.log('bar') }
}
// lets me know 'e' is missing, but makes types any
const foo2Vals: JustKeysOfFooVals = {
a: 'string',
b: 10,
c: Promise.resolve('string') ,
e: () => { console.log('bar') }
}
Is this possible?