Skip to content

Commit

Permalink
chore(types): tweaks to get types passing again
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 19, 2023
1 parent a2a36c6 commit 2b5f96c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 10 additions & 6 deletions packages/SwingSet/src/kernel/state/kernelKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export function commaSplit(s) {
return s.split(',');
}

/**
* @param {unknown} m
* @returns {asserts m is string}
*/
function insistMeterID(m) {
assert.typeof(m, 'string');
assert.equal(m[0], 'm');
Expand Down Expand Up @@ -553,14 +557,16 @@ export default function makeKernelKeeper(kernelStorage, kernelSlog) {
* Allocate a new koid.
*
* @param {string} ownerID
* @param {undefined | bigint} id
* @param {bigint} [id]
* @returns {string}
*/
function addKernelObject(ownerID, id = undefined) {
function addKernelObject(ownerID, id) {
// providing id= is only for unit tests
insistVatID(ownerID);
if (id === undefined) {
id = Nat(BigInt(getRequired('ko.nextID')));
// XXX https://github.com/Agoric/agoric-sdk/issues/4620
assert.typeof(id, 'bigint');
kvStore.set('ko.nextID', `${id + 1n}`);
}
kdebug(`Adding kernel object ko${id} for ${ownerID}`);
Expand Down Expand Up @@ -988,11 +994,9 @@ export default function makeKernelKeeper(kernelStorage, kernelSlog) {
insistMeterID(meterID);
assert.typeof(delta, 'bigint');
Nat(delta);
/** @type { bigint | string } */
let remaining = getRequired(`${meterID}.remaining`);
const remaining = getRequired(`${meterID}.remaining`);
if (remaining !== 'unlimited') {
remaining = Nat(BigInt(remaining));
kvStore.set(`${meterID}.remaining`, `${remaining + delta}`);
kvStore.set(`${meterID}.remaining`, `${Nat(BigInt(remaining)) + delta}`);
}
}

Expand Down
10 changes: 9 additions & 1 deletion packages/time/src/timeMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const relLike = (left, right, relValue) => {
// the `TimeMathType`, since that is the documentation that shows up
// in the IDE. Well, at least the vscode IDE.

/**
* @param {Timestamp} abs
* @returns {bigint}
*/
const absValue = abs => {
if (typeof abs === 'bigint') {
return Nat(abs);
Expand All @@ -111,6 +115,10 @@ const absValue = abs => {
return Nat(abs.absValue);
};

/**
* @param {RelativeTime} rel
* @returns {bigint}
*/
const relValue = rel => {
if (typeof rel === 'bigint') {
return Nat(rel);
Expand Down Expand Up @@ -200,7 +208,7 @@ const modRelRel = (rel, step) =>
* @param {Timestamp | RelativeTime} right
* @param {bigint} v1
* @param {bigint} v2
* @returns {RankComparison}
* @returns {-1 | 0 | 1}
*/
const compareValues = (left, right, v1, v2) => {
sharedTimerBrand(left, right);
Expand Down

0 comments on commit 2b5f96c

Please sign in to comment.