0

I have an set of data for which I need to specify type in typescript (type any is not recommended). 'xyzzy': (2) [Array(4), 1],

I get error when i specify its type as object. Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. No index signature with a parameter of type 'string' was found on type '{}'.

2
  • Is it nessesarily for object keys to be a strings? Commented Sep 30, 2021 at 12:43
  • For my data, i am getting key as string (the label and color) Commented Sep 30, 2021 at 12:45

1 Answer 1

1

You can specify new type with type keyword;

type MyType = {
  xyzzy: [number[], number],
  abs: [number[], number]
}

And then use this declaration

const something: MyType = {
  xyzzy: [[0, 1, 2, 3], 1],
  abs: [[0, 1, 2, 3], 0],
}
Sign up to request clarification or add additional context in comments.

2 Comments

How can i specify the value or write exactly, if i am getting data object as props from other component. Currently i am specifying it in my interface like : interface legendProps { data: any } i need to get ride of any here
Also can anybody tell me what will be type of this: let labelFormat: any = d3.format(".01f"); Now i have given any (which is not recommended)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.