【发布时间】:2019-09-22 08:36:05
【问题描述】:
我正在做一个个人项目来尝试学习 Angular 框架。我目前是它的新手,但我已经设法(我认为)在打字稿中正确包含 javascript bigint 数字类型(通过在 tsconfig.json 文件中定位 esnext 版本),因为这工作正常:
export class Particule {
public name: String;
public amount: bigint;
public cost: bigint;
constructor(name: String, amount: bigint, cost: bigint)
{
this.amount=amount;
this.name=name;
this.cost=cost;
}
public increment(): void {
this.amount += BigInt(1); // <<< this line compiles, no problem
}
/* ... */
}
但是,如果我将 increment() 方法的内容替换为:this.amount += 1n;,我会收到以下错误:
ERROR in ./src/app/entities/particule.ts 8:24
Module parse failed: Identifier directly after number (8:24)
You may need an appropriate loader to handle this file type.
| }
| increment() {
> this.amount += 1n;
| }
这不是一个中继“大”问题(看看我在那里做了什么:D),因为一切都适用于 BigInt() 调用,但我想知道是否有办法在我的项目中直接使用 bigint 文字!
感谢您的回答。
【问题讨论】:
-
Babel/TypeScript 应该更新其编译器以获取该信息帐户。将其作为错误报告给 Angular 团队,Théby 可能会处理它...
-
实际上,@Olivier,您使用的是哪个版本的
typescript?
标签: javascript angular typescript bigint