'Use generic as object key

I have a following situation, I have a react Tabs component. It's props have following types:

type SingleTab<T> = {
  name: string;
  count?: number;
  value: T;
}

type DataKeys<T extends keyof string> = { [key in T]: number };

export type TabsProps<T> = {
  data: Array<SingleTab<T>>;
  handleChangeTab: (newTabValue: T) => void;
  activeTab: T;
  tabCountData?: DataKeys<T>;
}

The problem is I can't manage to make T or DataKeys to be a string. That's the error I'm recieving:

(type parameter) T in type TabsProps<T> Type 'T' does not satisfy the constraint 'number | unique symbol | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | ... 35 more ... | "at"'.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source