作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为国际象棋游戏构建一个 Angular 应用程序。我想使用 chess.js 库 https://github.com/jhlywa/chess.js/blob/master/README.md使用 https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/chess.js 中声明的类型
但是每当我运行应用程序时,运行时都会出现错误。
我已经通过 npm 安装了软件包
npm install --save chess.js @types/chess.js
import {Chess, ChessInstance} from "chess.js"
@Injectable({
providedIn: 'root'
})
export class GameService {
private chess: ChessInstance = new Chess()
constructor() {}
...
}
core.js:15724 ERROR Error: Uncaught (in promise): TypeError: chess_js__WEBPACK_IMPORTED_MODULE_4__.Chess is not a constructor
TypeError: chess_js__WEBPACK_IMPORTED_MODULE_4__.Chess is not a constructor
import * as Chessjs from "chess.js"
@Injectable({
providedIn: 'root'
})
export class GameService {
private chess: Chessjs.ChessInstance = new Chessjs.Chess()
constructor() {}
...
}
最佳答案
我无法让它与打字一起工作,因为 Chess
未定义为 class
但作为 const
所以首先卸载类型:
npm uninstall --save @types/chess.js
import * as Chess from "chess.js
chess:any = new Chess();
import { ChessInstance } from 'chess.js'
ChessReq:any = require('chess.js');
Chess:ChessInstance = new this.ChessReq();
Chess.header()
例如编辑器上出现的类型
关于angular - "Not a constructor"库和 Angular 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58598457/
我是一名优秀的程序员,十分优秀!