microsoft/typescript-go · error

Publishing as 'typescript' requires a version before selecti

Error message

Publishing as 'typescript' requires a version before selecting an npm tag.

What it means

getPublishTag() requires a non-empty version before choosing an npm dist-tag when publishing as 'typescript'. With the current getVersion() (which either returns the hardcoded nativePreviewReleaseVersion or throws on parse failure), an empty version is effectively unreachable; this is a defensive invariant against future refactors.

Source

Thrown at Herebyfile.mjs:1235

        throw new Error("Failed to extract version from version.go");
    }

    let version = match[1];
    if (options.setPrerelease) {
        version += `-${options.setPrerelease}`;
    }
    else if (match[2]) {
        version += match[2];
    }

    return version;
});

function getPublishTag() {
    if (publishAsTypescript) {
        const version = getVersion();
        if (!version) {
            throw new Error("Publishing as 'typescript' requires a version before selecting an npm tag.");
        }
        const match = version.match(/-(dev|beta|rc)(?:[.-]|$)/);
        if (match?.[1]) return match[1] === "dev" ? "next" : match[1];
        if (version === nativePreviewReleaseVersion) return "latest";
        throw new Error(`Refusing to publish 'typescript' with the latest tag from non-release version ${version}.`);
    }
    return "latest";
}

const extensionDir = path.resolve("./_extension");
const nightlyExtensionDir = path.resolve("./_extension-nightly");
const builtNpm = path.resolve("./built/npm");
const builtVsix = path.resolve("./built/vsix");
const builtPublishedPlatformPackages = path.resolve("./built/published-platform-packages");
const builtSignTmp = path.resolve("./built/sign-tmp");
const publishedTypeScriptAliasPackageName = "@typescript/bundled-typescript";
const releasePackageEnv = { COREPACK_ENABLE_STRICT: "0" };

View on GitHub (pinned to 1bcfa18d79)

Solutions

  1. Set nativePreviewReleaseVersion to a full semver string or leave it undefined
  2. Keep getVersion() throwing on parse failure rather than returning empty values

Example fix

// before
const nativePreviewReleaseVersion = "";

// after
const nativePreviewReleaseVersion = undefined;
Defensive patterns

Strategy: validation

Validate before calling

const v = getVersion();
if (typeof v !== "string" || v.length === 0) {
  throw new Error("getVersion() must return a non-empty semver string");
}

Type guard

/** @param {unknown} v @returns {v is string} */
function isNonEmptyVersion(v) { return typeof v === "string" && v.length > 0; }

Prevention

When it happens

Trigger: Only if getVersion() is changed to return an empty string, e.g. nativePreviewReleaseVersion set to "" (falsy, bypasses the constant path) while version.go parsing is skipped or altered.

Common situations: Refactoring getVersion/getPublishTag; setting nativePreviewReleaseVersion to an empty string instead of undefined.

Related errors


AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16). Data as JSON: /api/errors/68f83bdfc9db94da. Report an issue: GitHub.