I want to achieve a generic type that will have a parametric key, like that (not valid TS example):
type PaginatedData<TKey, TData> = {
[TKey]: Array<TData>
meta?: {
limit: number
offset: number
}
}
Ideally the requisites are:
- should not be allowed to pass
metastring asTKey - the key of the array items should be generic I need to pass it from the outside..
I've already tried with:
type PaginatedData<TKey extends string, TData> = {
[key in TKey]: Array<TData>
} & {meta?: {limit: number, offset: number}}
But it breaks the 1. constraint