LayaIde 和 Vscode 有一点差别
当使用如下命令时 引入类型的时候 不会自动引入
npm install --save @types/autobahn
你需要手动 import 很难受的时 连提示也不会有
但是如果你引用了 就会有提示
具体为什么会这样 我不太清楚,也许是官方在index.html 中使用js库 不希望你在代码中如下情况
import { Connection } from "autobahn";
如果你只是想要提示的话,其实很简单
直接拷贝 node_modules\@types\autobahn\index.d.ts 这个文件到 工程的libs 目录中
也就是把上边的
///
export = autobahn;
删掉
这样就和Laya库的格式比较像 只是多了个命名空间
declare namespace autobahn {
export class Session {
id: number;
realm: string;
isOpen: boolean;
features: any;
..................................[/code]然后在ts文件中
[code]new autobahn.
引用华丽丽的出现了
如果谁有更好的方法 一起讨论研究..