microsoft/typescript-go · error · Error
Failed to extract version from version.go
Error message
Failed to extract version from version.go
What it means
Per-checker type dumps are written by typeTracer.DumpTypes: it builds a JSON array where each traced type is serialized with json.MarshalWrite into a strings.Builder, with the type's line number matching its type ID. This error wraps a marshal failure for the specific typ.Id() that failed, after which the whole types_N.json for that checker is abandoned (StopTracing wraps it further as 'failed to dump types for checker %d'). The most common real cause is an unencodable value inside a type descriptor — e.g. a NaN/Inf float, or a value type the JSON shim rejects.
Source
Thrown at Herebyfile.mjs:1217
try {
deferred.resolve(this._action());
}
catch (e) {
deferred.reject(e);
}
}
}
const getVersion = memoize(() => {
if (nativePreviewReleaseVersion) {
return nativePreviewReleaseVersion;
}
const f = fs.readFileSync("./internal/core/version.go", "utf8");
const match = f.match(/var version\s*=\s*"(\d+\.\d+\.\d+)(-[^"]+)?"/);
if (!match) {
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.");
View on GitHub (pinned to 1bcfa18d79)
Solutions
- Reproduce with the same --trace flags and inspect the reported type ID (message includes it) using the checker's traced type list to find the offending value.
- Sanitize descriptor values in buildTypeDescriptor: convert NaN/Inf floats to strings or omit them; keep only encodable types (strings, numbers, bools, maps, slices).
- If using a custom JSON shim, test json.MarshalWrite against the failing descriptor directly and fix the shim (or fall back to encoding/json).
- Report upstream with the minimal repro — type-dependent marshal failures usually indicate a descriptor-field bug.
Example fix
// before: raw float that can be NaN leaks into the descriptor
args["value"] = f
// after: keep descriptors JSON-safe
if math.IsNaN(f) || math.IsInf(f, 0) {
args["value"] = fmt.Sprintf("%v", f)
} else {
args["value"] = f
} Defensive patterns
Strategy: try-catch
Try / catch
if err := tr.StopTracing(); err != nil {
if strings.Contains(err.Error(), "failed to marshal type") {
// message includes the failing type ID; timing trace may still be usable,
// but types_%d.json for that checker is incomplete — report upstream with repro
log.Printf("type serialization failed: %v", err)
}
} Prevention
- When extending buildTypeDescriptor, restrict values to strings/numbers/bools/maps/slices.
- Never pass NaN/Inf floats into descriptors; format them as strings.
- Unit-test DumpTypes over traced types after changing descriptor shapes or the JSON shim.
- Use the reported type ID from the message to isolate the offending type in repros.
When it happens
Trigger: StopTracing (which calls tracer.DumpTypes per checker) when buildTypeDescriptor produces a descriptor containing a value the marshaller refuses: NaN/±Inf floats from type display data, func/chan values, cycles not normalized by recursionIdentityMap, or a custom JSON shim (json.MarshalWrite from the project's json package) rejecting a shape it doesn't support.
Common situations: Tracing checkers that observed exotic types (arithmetic producing NaN in symbol displays, very deep/generic recursion); swapping or version-skewing the project's custom JSON encoder; changes to buildTypeDescriptor adding raw checker values that encoding/json would reject.
Related errors
- Found ${unusedBaselines.length} unused baseline file(s). Run
- No members found for enum ${def.name} in ${def.goFile}
- %w: %w
- _submodules/TypeScript does not exist; try running `git subm
- Cannot parse string enum value: ${goValue}
AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16).
Data as JSON: /api/errors/187f940893557fc7.
Report an issue: GitHub.