Интересно, что мне нужно сделать, чтобы убрать следующую ошибку из моего кода:
У меня есть эти интерфейсы:
export interface ClassifierTO {
id?: number;
classifierName?: string;
userId?: number;
intents?: Array<IntentTO>;
}
и:
export interface IntentTO {
id?: number;
intentName?: string;
classifierId?: number;
numberOfSamples?: number;
}
Они были автоматически сгенерированы с помощью openapi-generator
.
Когда я использовал это внутри метода class-component
из vue:
let intents = this.classifier.intents
.filter(intent => intent.intentName === "test")
.map(intent => intent.numberOfSamples);
Затем результат внутри консоли vs код:
Object is possibly 'undefined'
Что мне нужно изменить, чтобы это больше не воспринималось как ошибка? Версия машинописного текста - 3.8.3
, а это 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"
]
}