Skip to content

Commit af4e59a

Browse files
committed
fix: type-level arithmetic!
Working around microsoft/TypeScript#26382, which will likely never get solved.
1 parent 36e2906 commit af4e59a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎lib/min-version.js‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ const chalk = require('chalk');
88
const ErrorMessage = require('./error-message');
99
const PathHelpers = require('./path-helpers');
1010

11-
const minimalVersion = {major: 2, minor: 14};
12-
// prettier-ignore
13-
const supportedRange = `${minimalVersion.major}.${minimalVersion.minor}.0 <= v < ${minimalVersion.major + 1}.0.0`
11+
const minimalVersion = /** @type {const} */ ({major: 2, minor: 14});
12+
13+
// TS can't do arithmetic, so make sure the cast is right when bumping the major.
14+
const nextMajor = /** @type {3} */ (minimalVersion.major + 1);
15+
16+
const supportedRange = /** @type {const} */ (
17+
`${minimalVersion.major}.${minimalVersion.minor}.0 <= v < ${nextMajor}.0.0`
18+
);
1419

1520
/**
1621
* If given an input version string smaller than the hardcoded `minimalVersion`,

0 commit comments

Comments
 (0)