TS2322:类型“ number”不可分配给类型“ bigint”

时间:2020-10-12 20:23:18

标签: javascript

我不明白为什么?

export const CompanyProfileStub: Company = {
    id: 1
};

我该如何解决?

export interface Company {
    id: bigint;
}

1 个答案:

答案 0 :(得分:2)

基本上,您不能将Number分配给BigInt,因为它是另一种原语。 您可以使用BigInt的构造函数在JS中创建BigInt,如下所示:

const huge = BigInt(9007199254740991)

或在数字末尾使用n,如下所示:

const huge = 1n