"Object is possibly 'null'." 尽管可选链接

"Object is possibly 'null'." despite optional chaining

即使我使用的是可选链接和 TypeScript 4.6.3,我也得到 Object is possibly 'null'. ts(2531)

const path = fileInput?.files[0]?.path

tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",
    "useDefineForClassFields": true,
    "module": "esnext",
    "moduleResolution": "node",
    "strict": true,
    "jsx": "preserve",
    "sourceMap": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "lib": ["esnext", "dom"]
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

我做错了什么?

也对数组索引访问使用可选链接。

const path = fileInput?.files?.[0]?.path