繁体   English   中英

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

[英]Property 'showSaveFilePicker' does not exist on type 'Window & typeof globalThis'

const opts = {
      suggestedName: 'data',
      types: [
        {
          description: 'NewCSV',
          accept: { 'text/csv': ['.csv'] },
        },
      ],
    };
    const handle = await (window).showSaveFilePicker(opts);

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

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

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

似乎 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"]
   }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM