2017-10-07 61 views
0

我试图根据https://github.com/angular/angular-cli/wiki/stories-third-party-lib@angular/cli上使用@types/stats。 但是,当我尝试import * as STATS from 'stats.js'我得到了tslint错误。不能在@ angular/cli上使用Stats.js 1.4.4

[ts] Module '"stats.js"' resolves to a non-module entity and cannot be imported using this construct.

@类型/统计的index.d.ts

declare class Stats { 
    REVISION: number; 
    dom: HTMLDivElement; 
    /** 
    * @param value 0:fps, 1: ms, 2: mb, 3+: custom 
    */ 
    showPanel(value: number): void; 
    begin(): void; 
    end(): number; 
    update(): void; 
} 

declare module "stats.js" { 
    export = Stats; 
} 

src/Stats.js(Stats.js本身)

https://github.com/mrdoob/stats.js/blob/master/src/Stats.js

我想,为什么我得到错误的原因是@types/stats使用export =风格出口。

所以我应该使用import Stats = require('stats.js')但是@angular/cli默认使用"module": "es2015"

我该如何导入它?

+0

yes'import Stats = require('stats.js');'应该像类型def看起来像'declare module“stats.js”{export = Stats; }' – Kuncevic

回答

0

如果你确定你安装的东西都正确。

npm install stats-js npm install @types/stats-js

你应该能够将其导入这样的: import * as STATS from 'stats';没有” .js文件。

+0

感谢您的回复;) 我试图使用不* stats-js *包但是* stats.js *包。他们是不同的。 –