Is the heigh argument in Long constructor required?
webmaster128 opened this issue · comments
The type definitions in @types/long define a type constructor like this:
new( low: number, high?: number, unsigned?: boolean ): Long;
The optional height
allows users to write new Long(123)
. This is a problem as it makes it way too easy for callers to assume this is the correct number to Long conversion because it works for a very long time until it breaks.
The README marks heigh
as required. The implementation works fine if unset because undefined | 0
is 0
.
Is it safe to assume heigh
is required and this can be considered a bug in the types?
I don't think this is a bug. The official types shipped with the library define:
Lines 7 to 10 in ce11b4b
The comment states that provided values must be 32-bit. The correct way to construct a Long
from a number
is Long.fromNumber
:
Lines 77 to 80 in ce11b4b
The README, however, appears to be out of date, and high
should be optional there.
Thanks for the detailed answer and README fix!