* Coerce a `number | Long` to a `number`. * * Our "intValue" and "intArrayValue" widget protobuf fields represent their * values with sint64, because sint32 is too small to represent the full range * of JavaScript int values. Protobufjs uses `number | Long` to represent * sint64. However, we're
(value: number | Long)
| 1525 | * precision (which should not be possible!), throw an error instead. |
| 1526 | */ |
| 1527 | function requireNumberInt(value: number | Long): number { |
| 1528 | if (typeof value === "number") { |
| 1529 | return value |
| 1530 | } |
| 1531 | |
| 1532 | const longNumber = util.LongBits.from(value).toNumber() |
| 1533 | if (Number.isSafeInteger(longNumber)) { |
| 1534 | return longNumber |
| 1535 | } |
| 1536 | |
| 1537 | throw new Error( |
| 1538 | // eslint-disable-next-line @typescript-eslint/no-base-to-string -- Long has a toString() method |
| 1539 | `value ${value.toString()} cannot be converted to number without a loss of precision!` |
| 1540 | ) |
| 1541 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…