I am defining a api for a typescript frontend/backend application.
Now I want to write an interface that is allowed to contain all available keys defined in an other interface, prefixed with filter.
Lets say I have a user interface
interface User {
firstname: string;
lastname: string;
}
A User request can be filtered, so my general Request ist extended with FilteredRequest
interface FilteredRequest<T> {
[key: 'filter.' + keyof T]: any;
}
Is this possible with typescript?
Ok because this is not possible right now.
Also not prefixing the key with someting does not work
interface FilteredRequest<T> {
[key: keyof T]: any;
}
An index signature parameter type must be 'string' or 'number'.ts(1023)
But keyof is designed to return a string or number
type FilteredRequest<T> = { [key in keyof T]: any; }or usingRecord:type FilteredRequest<T> = Record<keyof T, any>