diff --git a/semver/_parse_comparator.ts b/semver/_parse_comparator.ts index b174657547fbb..c2361e90634c5 100644 --- a/semver/_parse_comparator.ts +++ b/semver/_parse_comparator.ts @@ -33,8 +33,14 @@ export function parseComparator(comparator: string): Comparator { const semver = groups.major ? { major: parseNumber(groups.major, "Invalid major version"), - minor: parseNumber(groups.minor, "Invalid minor version"), - patch: parseNumber(groups.patch, "Invalid patch version"), + minor: parseNumber( + groups.minor!, + "Invalid minor version", + ), + patch: parseNumber( + groups.patch!, + "Invalid patch version", + ), prerelease: prerelease ? parsePrerelease(prerelease) : [], build: buildmetadata ? parseBuild(buildmetadata) : [], } diff --git a/semver/parse.ts b/semver/parse.ts index 470ce0690191f..73d74ac1a8376 100644 --- a/semver/parse.ts +++ b/semver/parse.ts @@ -27,9 +27,9 @@ export function parse(version: string): SemVer { const groups = version.match(FULL_REGEXP)?.groups; if (!groups) throw new TypeError(`Invalid Version: ${version}`); - const major = parseNumber(groups.major, "Invalid major version"); - const minor = parseNumber(groups.minor, "Invalid minor version"); - const patch = parseNumber(groups.patch, "Invalid patch version"); + const major = parseNumber(groups.major!, "Invalid major version"); + const minor = parseNumber(groups.minor!, "Invalid minor version"); + const patch = parseNumber(groups.patch!, "Invalid patch version"); const prerelease = groups.prerelease ? parsePrerelease(groups.prerelease) diff --git a/semver/parse_range.ts b/semver/parse_range.ts index 94c88d5c0c0b1..c429d1a027607 100644 --- a/semver/parse_range.ts +++ b/semver/parse_range.ts @@ -5,7 +5,7 @@ import { OPERATOR_XRANGE_REGEXP, XRANGE } from "./_shared.ts"; import { parseComparator } from "./_parse_comparator.ts"; import { parseBuild, parsePrerelease } from "./_shared.ts"; -function isWildcard(id: string): boolean { +function isWildcard(id?: string): boolean { return !id || id.toLowerCase() === "x" || id === "*"; } @@ -50,9 +50,9 @@ function parseHyphenRange(range: string) { if (isWildcard(rightGroups.major)) { to = ""; } else if (isWildcard(rightGroups.minor)) { - to = `<${+rightGroups.major + 1}.0.0`; + to = `<${+rightGroups.major! + 1}.0.0`; } else if (isWildcard(rightGroups.patch)) { - to = `<${rightGroups.major}.${+rightGroups.minor + 1}.0`; + to = `<${rightGroups.major}.${+rightGroups.minor! + 1}.0`; } else if (rightGroups.prerelease) { to = `<=${rightGroups.major}.${rightGroups.minor}.${rightGroups.patch}-${rightGroups.prerelease}`; diff --git a/semver/range_intersects.ts b/semver/range_intersects.ts index 9dc802c40f701..471ef54d42b32 100644 --- a/semver/range_intersects.ts +++ b/semver/range_intersects.ts @@ -12,7 +12,7 @@ function rangesSatisfiable(ranges: Range[]): boolean { function comparatorsSatisfiable(comparators: Comparator[]): boolean { // Comparators are satisfiable if they all intersect with each other for (let i = 0; i < comparators.length - 1; i++) { - const c0 = comparators[i]; + const c0 = comparators[i]!; for (const c1 of comparators.slice(i + 1)) { if (!comparatorIntersects(c0, c1)) { return false;