1

How to define the data type of value in the nodejs function written in typescript, so that error of Object is of type unknow can be solved ?

enter image description here

1
  • It's not possible to answer this with the given information because it depends on the type of res.get(). Of you post a minimal reproducible example and include the relevant code in you as text then we can help you much better with this. Commented Dec 15, 2020 at 18:49

1 Answer 1

3

You need to implement type for value. Try smth like this:

type valueType = {
  id: string,
  field1: number,
  field2: string,
}

const obj = {
  a: {
    id: '12',
    field1: 1,
    field2: 'asdas',
  }
}

for (const [key, value] of Object.entries(obj)) {
  const typedValue: valueType = value;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.