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'.
:outputDataisnt a type (its a variable) What are you expecting the output to look like?outputData. and your output doesnt have the type ofoutputData. Did you mean `const output = { postcode: '0000' submitted: 'yes' } ?