near-runtime-ts
near-runtime-ts copied to clipboard
`Vector.length` should have type `u32`
The following function in Vector
:
/**
* @returns The length of the vector.
*/
get length(): i32 {
if (this._length < 0) {
this._length = storage.get<i32>(this._lengthKey, 0);
}
return this._length;
}
should have a return type of u32
so that x.length
can be compared against a u32
value
(for(let i = 0; i <= x.length; i++)
)
There are two separate fixes for this, casting the type on return:
/**
* @returns The length of the vector.
*/
get length(): u32 {
if (this._length < 0) {
this._length = storage.get<i32>(this._lengthKey, 0);
}
return <u32>this._length;
}
the other fix is to replace
this._length = -1
in the constructor with
this._length = storage.get<u32>(this._lengthKey, 0);
and changing the type of _length
to u32
I can open a PR to fix either of these, but wanted to check which is more fitting with the style of the other code.