typescript 属性“showSaveFilePicker”在类型“Window & typeof globalThis”上不存在

6l7fqoea  于 2023-06-07  发布在  TypeScript
关注(0)|答案(2)|浏览(604)
const opts = {
      suggestedName: 'data',
      types: [
        {
          description: 'NewCSV',
          accept: { 'text/csv': ['.csv'] },
        },
      ],
    };
    const handle = await (window).showSaveFilePicker(opts);

现在我有类型错误Property 'showSaveFilePicker' doesn't exist on type 'Window & typeof globalThis',提供类型为any解决了类型错误的问题。

const handle = await (<any>window).showSaveFilePicker(opts);

但它仍然会显示eslint错误Unsafe call of an any typed value。因此,我知道的唯一解决方案是禁用文件的eslint。有没有其他方法可以避免类型错误和eslint错误?

7gcisfzg

7gcisfzg1#

TypeScript的文件系统访问API的类型定义目前似乎被破坏了:https://github.com/microsoft/vscode/issues/141908
现在,尝试安装@types/wicg-file-system-access包来修复类型:

# Yarn
yarn add --dev @types/wicg-file-system-access

# NPM
npm install --save-dev @types/wicg-file-system-access

您还需要更新tsconfig.json的types字段:

"compilerOptions": {
    "types": [ "@types/wicg-file-system-access"]
   }
muk1a3rh

muk1a3rh2#

我不得不在我的Angular项目主目录中添加npm i @types/wicg-file-system-access

相关问题