Issue
I have input data in this form:
const input = {
postcode: ['0000']
submitted: ['yes']
}
const output = {
postcode: '0000'
submitted: 'yes'
}
How to create interface for input data?
I tried:
interface inputData {
postcode: string[]
submitted: string[]
}
interface outputData {
postcode: string
submitted: string
}
But I get error while applying it:
const extract = (input: inputData[]): outputData => {
for (const key in input) {
if (Object.hasOwnProperty.call(input, key)) {
input[key] = input[key][0]; // Error here
}
}
const output: any = input;
return output;
}
Error: Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'inputData'. Property '0' does not exist on type 'inputData'.
Solution
You can define an interface with an indexer:
interface EnumServiceGetOrderBy {
[index: number]: { id: number; label: string; key: any };
}
Answered By - Matte
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.