🛡

[TypeScript] 非常に大きな整数はbigint型を使う

に公開

はじめに

この記事では、TypeScript の bigint 型 をまとめております。

参考資料

結論

1. 安全な整数の最小値を扱う

// 安全な整数の最小値
const num:bigint = -2 ** 53

2. 安全な整数の最大値を扱う

// 安全な整数の最大値
const num: bigint = 2 ** 53;

3. bigint で小さい値を扱う

// Type 'number' is not assignable to type 'bigint'.
const num: bigint = 100;
GitHubで編集を提案

Discussion