Reputation: 51
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 ?
Upvotes: 1
Views: 1449
Reputation: 775
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;
}
Upvotes: 3