I want to create an object of type Partial
, where the keys will be some combination of 'a', 'b', or 'c'. It will not have all 3 keys (edit: but it will at least have one). How do I enforce this in Typescript? Here's more details:
// I have this:
type Keys = 'a' | 'b' | 'c'
// What i want to compile:
let partial: Partial = {'a': true}
let anotherPartial: Partial = {'b': true, 'c': false}
// This requires every key:
type Partial = {
[key in Keys]: boolean;
}
// This throws Typescript errors, says keys must be strings:
interface Partial = {
[key: Keys]: boolean;
}
The two methods I've tried above (using mapped types and interfaces) don't achieve what I want. Can anyone help here?