【问题标题】:The type definition of Plotly.animate not found未找到 Plotly.animate 的类型定义
【发布时间】:2022-11-08 16:47:13
【问题描述】:

我在 Vue@3.2.38 项目中使用带有 Typescript@4.5.5 的 plotly.js,我通过以下命令安装了它:

npm install plotly.js-dist-min
npm install @types/plotly.js-dist-min

我在带有 Volar 扩展名的 Visual Studio Code 中编写代码。

当我使用动画函数 (https://plotly.com/javascript/animations/) 时,VSCode 在

Plotly.animate()
       ^^^^^^^^

也就是说

“类型'typeof import(“/WORKSPACE-PATH/node_modules/@types/plotly.js/index”)'上不存在属性'animate'”

这是否意味着 @types/plotly.js-dist-min 不包含“动画”函数的类型?

以及如何解决?

请原谅我糟糕的英语。谢谢你。

目录

dist/
node_modules/
  - @types/
     - plotly.js/
        - lib/
        - index.d.ts
        - LICENSE
        - package.json
        - README.md
     - plotly.js-dist-min/
        - index.d.ts
        - LICENSE
        - package.json
        - README.md
    - others
  - plotly.js-dist-min
     - LICENSE
     - package.json
     - plotly.min.js
     - README.md
  - others
public/
  - index.html
src/
  - others
.eslintrc.js
.gitignore
babel.config.js
package-lock.json
package.json
README.md
tsconfig.json
vue.config.js

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "moduleResolution": "node",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "useDefineForClassFields": true,
    "resolveJsonModule": 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"
  ]
}

【问题讨论】:

  • 打字的source 字面上是plotly.js 的打字,所以我猜你也需要安装@types/plotly.js
  • 感谢您的评论,但另外安装 @types/plotly.js 对我不起作用。
  • 我们可以看到您的 TSConfig 和文件夹结构吗?
  • 好的,信息已添加到问题中。

标签: typescript plotly.js


【解决方案1】:

@types 定义要么不完整,要么不是最新的。我还偶然发现了一些缺失的类型。

截至今日:

"@types/plotly.js": "2.12.1",
"plotly.js-basic-dist": "2.16.1",

有人需要为开源项目做出贡献。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 2023-03-20
    • 2018-04-05
    • 2016-05-15
    • 2015-12-09
    相关资源
    最近更新 更多