Find the Required Fields Still Missing

Write the code, see it run, pass the checks.

The problem

  • hard
  • Code

Export RequiredKeys<T>, the keys of T that can't be left out, and OptionalKeys<T>, the ones marked optional. A field typed string | undefined but not marked optional still counts as required. Then write missingKeys<T>(draft, required): return the keys from required whose value in draft is missing or undefined, in the order given (empty strings and 0 count as present). Type it so draft may leave out any field of T, required only takes T's required keys, and the result is a list of them.

Your code must pass

  • Lists missing and undefined keys, in order
  • Counts empty strings and zero as present
  • Has no type errors
  • RequiredKeys lists the fields that can't be left out
  • OptionalKeys lists the optional fields
  • Only takes required keys