0

I want create a type called 'DataSource' with base attrs like 'index'.it has other unknown attr names, they value type is 'BaseClassData'.

interface DataSource{
  index: number;
  [key: string]: BaseClassData;
}

tslint send a error 'Property 'index' of type 'number' is not assignable to string index type 'BaseClassData', how to fix it

silk
  • 189
  • 2
  • 11
  • Can you show an example of the code that is using this & generates the error? Maybe use https://www.typescriptlang.org/play – olore May 11 '21 at 01:45
  • I've closed this as a duplicate of [this question](https://stackoverflow.com/questions/61431397/how-to-define-typescript-type-as-a-dictionary-of-strings-but-with-one-numeric-i), assuming that you want a type where the index signature does not apply to the known keys. Unfortunately, no such type exists in TypeScript, so there are just a variety of workarounds. Translating the code in that answer here yields [this](https://tsplay.dev/NalMnw), FYI. If I have misunderstood what you are asking about, please edit the question to elaborate and I will vote to re-open the question. Good luck! – jcalz May 11 '21 at 01:54

0 Answers0