Typescript Aurelia CLI可以';t导入chart.js类型脚本

Typescript Aurelia CLI可以';t导入chart.js类型脚本,typescript,aurelia,Typescript,Aurelia,我正在将typescript与aurelia/aurelia cli一起使用。我已经安装了npmchart.js,并将其添加到我的aurelia.json文件中: "dependencies": [ ... { "name": "chartjs", "path": "../node_modules/chart.js/dist", "main": "Chart" }, ] 我还做过打字: typings inst

我正在将typescript与aurelia/aurelia cli一起使用。我已经安装了npm
chart.js
,并将其添加到我的
aurelia.json
文件中:

"dependencies": [
      ...
      {
        "name": "chartjs",
        "path": "../node_modules/chart.js/dist",
        "main": "Chart"
      },
]
我还做过打字:

typings install dt~chart.js --global --save
现在我正试图将它导入到我的一个组件中

import * as Chart from 'chartjs'
但我得到了一个错误:

Cannot find module 'chartjs'.
我也试过:

... from 'chart'
... from 'Chart'
... from 'Chart.js'
... from 'chartjs'
import * as chart ...
import * as chartjs ...

我知道Chart.js与Aurelia一起工作,因为我们在研讨会的一个演示应用程序中使用它。在演示应用程序中,它是这样导入的:
从“chartjs”导入图表但这是ES2015,不是TypeScript

此外,在
aurelia.json
中,配置应该如下所示:

      {
        "name": "chartjs",
        "path": "../node_modules/chart.js/Chart.min",
        "exports": "Chart"
      }

您是否已尝试声明空模块?e、 g在类似于
index.d.ts
的声明文件中,添加:

declare module "chart.js";
我发现这是导入第三方库的一个很好的起点。更多信息可在此处找到:

如果没有错误,并且您可以使用普通的js
chart.js
函数,这意味着已经包含了库,但是没有包含类型

此外,如果您使用的是Typescript 2.0,我认为您应该安装以下类型:

npm install --save @types/chartjs

我可以通过更改import和aurelia.json文件使其正常工作

aurelia.json

{
    "name": "chartjs",
    "path": "../node_modules/chart.js/dist/Chart.min"
},
进口声明

import 'chartjs';

如果我删除index.d.ts文件的所有内容,只添加
声明模块“chart.js”然后错误消失。什么意思是库已经包含,而类型没有包含?因此,如果您这样声明一个模块,那么从该模块导入的所有内容都将具有any类型。您不再进行任何类型检查,但只要正确加载了模块,就应该能够使用js。如果模块尚未加载,而您尝试使用它,则会出现一系列运行时错误。js库并不总是有类型定义,因此,通过这种方式,您可以使用没有任何typedef的普通js库。当我像这样声明模块时,visual studio错误消失了,但当应用程序尝试编译时,它抛出了一个错误,即找不到“chart.js”,程序崩溃了。你们是在使用chartjs v1还是v2?看起来我有2.4.0那么为什么需要exports属性呢?我认为这是针对使用全局脚本的遗留库的,现在可能不再是这样了。我发布的配置最后一次更新是在8月份。