typescript - 在 typescript 项目中导入 matter-js

标签 typescript matter.js

我找到了这个文件:

https://www.npmjs.com/package/@types/matter-js

我执行这一行:

npm install --save @types/matter-js

在根 ts 文件中我收到错误消息:

'Matter' refers to a UMD global, but the current file is a module. Consider adding an import instead.

代码如下:

///<reference path="matter-js.d.ts"/>

import Ioc from "./libs/ioc";
let master = new Ioc();
console.log(master);
console.log(Matter);

浏览器错误:

app.ts:11 Uncaught ReferenceError: Matter is not defined

我需要加载 matter-js.js 库吗?

如果我输入:

import matter from 'matter-js'

我得到:

Module ''matter-js'' has no default export.

最佳答案

您可以尝试使用 import * as matter from 'matter-js' 加载它,应该可以。

关于typescript - 在 typescript 项目中导入 matter-js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49734671/

相关文章:

angular - Lodash index.d.ts :244:12 Angular2 web pack build 中的重复标识符 '_'

javascript - Angular 2 ng2-completer获取选定的项目值

collision - Matter.js 碰撞过滤不起作用

physics - 如何防止 [circle] body 滑入静态 body 之间的 0px 间隙

javascript - 如何在 Phaser 3 中使用 Sprite 的 X 和 Y 位置来实现 "Fling"物理?

javascript - Matter.js 如何制作一个正确落地的盒子?

node.js - 在 sequelize getter 和 setter 函数中使用时出现 "Argument of type is not assignable to parameter of type"错误

typescript - 如何从 TypeScript 的接口(interface)中排除键

visual-studio - Visual Studio 2012 - 如何将多个构建操作分配给 TypeScript 文件

javascript - 了解 Box : this, 推送和弹出的 Matter.js 代码