【发布时间】:2021-07-14 09:58:14
【问题描述】:
我的构造函数在接口中看不到方法,我遇到了这样的问题: “Board”类错误地实现了“IBoard”接口。 “Board”类型中缺少属性“makeBoard”,但在“IBoard”类型中是必需的。
如何处理?
interface ICell {
x: number,
y: number,
showBoard(): void,
ctx: CanvasRenderingContext2D
}
export interface IBoard {
ctx: CanvasRenderingContext2D,
cell: Array<ICell>;
canvas: HTMLCanvasElement,
createCell(x:number, y:number, ctx:CanvasRenderingContext2D, color:string): void,
createCells(): void,
showBoard(): void,
makeBoard(): void
}
export class Board implements IBoard {
cell: Array<ICell> = [];
canvas = document.getElementById('chessBoard-canvas') as HTMLCanvasElement;
ctx = this.canvas.getContext('2d') as CanvasRenderingContext2D;
constructor() {
this.makeBoard();
}
}
【问题讨论】:
标签: javascript typescript