I'm hitting this wall since days now and I'm not sure anymore if I'm the problem or if typescript is broken...
I defined a generic class with the generic extending Record<string, string>
:
class DbTable<ColumnDefinitions extends Record<string, string>> { /* ... */ }
At a later point I want to use the exact keys (e.g. 'id' | 'name'
instead of just string
), so I use the keyof
operator on the generic, like this:
function selectFields(fields: (keyof ColumnDefinitions)[]) { /* ... * / }
But keyof ColumnDefinitions
resolves to string | number | symbol
instead of just being of type string
.
What did I miss?!
Here is a TS playground link with an example.