【发布时间】:2021-09-04 07:36:57
【问题描述】:
我正在尝试使用带有 p5.js 的 Typescript 编写一些草图。我已经通过 npm 安装了 p5 和 @types/p5。
在我的草图中,我尝试使用 createVector 方法创建一个 Vector,但打字稿似乎找不到它。我只是收到错误“类型'typeof import(“local_path_stuff/node_modules/@types/p5/index.d.ts”)'上不存在属性'createVector'。”
有人对修复此错误有任何建议吗?
/// @ts-check
/// <reference path="../../node_modules/@types/p5/global.d.ts" />
import p5 from "p5";
export abstract class BaseEntity {
protected pos: p5.Vector;
protected id: number;
protected entityType: number;
constructor(id: number, entityType: number, pos?: p5.Vector){
this.id = id;
this.entityType = entityType;
if(pos) {
this.pos = pos;
} else {
this.pos = p5.createVector(0,0); //Error here
}
}
abstract update(dt: number): void;
abstract draw(s: p5): void
}
【问题讨论】:
标签: typescript p5.js