... There doesn't seem to be an index signature with a parameter of type 'string' on the 'TestObject' type.
I am attempting to iterate through an object in TypeScript using the code below.
Interestingly, it works in StackBlitz but not in my Angular project within VS Code...
A similar or possibly the same question has been discussed here, where they recommend either creating a new type or resorting to 'any'.
Given that it runs successfully in StackBlitz but not in VS Code, I suspect there might be an issue with my project settings, although I'm unsure where to start looking.
export class HelloComponent {
@Input() name: string;
myTestObject: TestObject = {
id: 1,
name: 'Bob',
age: 40,
gender: 'male',
};
constructor() {
this.iterateThroughObject();
}
iterateThroughObject(): void {
Object.keys(this.myTestObject).forEach((property) => {
console.log(this.myTestObject[property]);
});
}
}
The 'TestObject' type is defined in another class
export interface TestObject {
id: number;
name: string;
age: number;
gender: string;
}
Is this possibly an issue with my tsconfig.json file?
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2020",
"module": "es2020",
"lib": [
"es2020",
"dom"
]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}