r/typescript•
reonZ

Modifying keys type and recursion

I have the recursive part done i think:

type Updatable<O> = O extends object
    ? {
          [K in keyof O]?: Updatable<O[K] | true>;
      }
    : O;

This properly allows me to not provide a key if not needed and if needed, i can give it a value of `true`

Now onto the second problem, i need the keys of the `Updatable` to be `"myKey"` or `"-=myKey"`, but i can't figure out how to make this.

Also, the ideal would be to actually have `["myKey"]?: Updatable<O[K]>` and `["-=myKey"]: true`

Posted Mar 15, 2024, 2:04 PM UTC

15

Comments aren't archived yet

This post had 5 comments on Reddit. Comments for this period haven't been loaded into the archive yet.