我想知道我需要做什么才能从我的代码中删除以下错误:
我有这些界面:
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"
]
}