Is there a way in Typescript to create an object of type Partial
with keys that can only be a combination of 'a', 'b', or 'c'? The object should not have all 3 keys, but it must have at least one. Here's what I've attempted so far:
// Defined keys:
type Keys = 'a' | 'b' | 'c'
// Desired object structure:
let partial: Partial = {'a': true}
let anotherPartial: Partial = {'b': true, 'c': false}
// Attempt using mapped types (does not work as intended):
type Partial = {
[key in Keys]: boolean;
}
// Attempt using interfaces (also not achieving the desired result):
interface Partial = {
[key: Keys]: boolean;
}
Neither of the methods I've tried seems to enforce the restriction I need. Can anyone provide a solution?