Keyof Type with String autocomplete TS

Viewed 126

So I was working on a type and wanted to get recommendation of an object's keys, and if I wanted to use another key, the type could fallback to a string type.

I know that the union type with a string basically is the every possible string, so no recommendations are given.

But why while this approach does not work string | keyof Database the following gives the desired result (string & {}) | DatabaseKeys> ?

Find more complete example in TS playground.

0 Answers
Related