我刚刚重新启动了Windows并希望编写一些代码,而我正在尝试将typescript编译到节点模块(.js文件),这些打字稿编译器没有输出正确的代码。 我举一个例子:
import { Size } from "./Utils/Size";
export class Canvas {
private canvasElement: HTMLCanvasElement;
private context: CanvasRenderingContext2D;
public constructor(options: CanvasOptions) {
let c: HTMLCanvasElement;
if (options.customCanvasId)
c = document.getElementById(options.customCanvasId) as HTMLCanvasElement;
else
c = document.createElement("canvas");
}
}
export interface CanvasOptions {
isResizable: boolean;
minResolution: Size;
maxResolution: Size;
customCanvasId?: string;
}
这将编译为:
export class Canvas {
constructor(options) {
this.c = document.createElement("canvas");
let c;
if (options.customCanvasId)
c = document.getElementById(options.customCanvasId);
as;
HTMLCanvasElement;
}
}
并且编译错误给了我:
Canvas.ts(10,56): error TS1005: ';' expected.
Canvas.ts(10,59): error TS1005: ';' expected.
Canvas.ts(11,3): error TS1128: Declaration or statement expected.
Canvas.ts(15,1): error TS1128: Declaration or statement expected.
如果我查看我的代码,我的所有内容都是oke,那么为什么输出不正确?
P.S。 我的tsconfig:
{
"compilerOptions":
{
"target": "es6",
"outDir": "../react-engine/src/engine-core"
}
}
我尝试格式化代码,但它没有任何帮助......
答案 0 :(得分:0)
Oke所以2分钟后我发现我做了npm i tsc
而不是npm i typescript
......
我感到很蠢......