I am puzzled about how to eliminate the following error that keeps popping up in my code:
Here are the interfaces I have defined:
export interface ClassifierTO {
id?: number;
classifierName?: string;
userId?: number;
intents?: Array<IntentTO>;
}
and:
export interface IntentTO {
id?: number;
intentName?: string;
classifierId?: number;
numberOfSamples?: number;
}
These interfaces were autogenerated using openapi-generator
.
When I try to use them within a method of the class-component
in Vue:
let intents = this.classifier.intents
.filter(intent => intent.intentName === "test")
.map(intent => intent.numberOfSamples);
The error message displayed in the VS Code console is:
Object is possibly 'undefined'
What changes do I need to make to resolve this error?
The TypeScript version being used is 3.8.3
and here is the content of tsconfig.json
:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}