{"slug": "one-rule-found-a-bug-that-typescripts-test-suite-missed", "title": "One rule found a bug that TypeScript’s test suite missed.", "summary": "Breakspec, a tool that checks code against invariant rules, found a bug in Microsoft's TypeScript compiler after 19 inputs: declaration files the compiler emits for constants that overflow to Infinity, such as `export default 1.7976931348623159e308;`, contain initializers like `declare const _default = Infinity;` that the same compiler then rejects with error TS1254. The bug, filed publicly as microsoft/TypeScript#64760, also affects TypeScript 6.0.3 and predates the Go rewrite, and no existing TypeScript test covered it. A fix written with Claude Code, which gives such constants the type `number` instead of an initializer, passed 300 fresh inputs and TypeScript's Go test suite of 64 packages plus a new compiler test, and is under review.", "body_md": "# Breakspec found a bug in Microsoft’s TypeScript compiler\n\nWe pointed Breakspec at the TypeScript repository with one rule: the declaration files the compiler writes must be valid TypeScript. It broke that rule after 19 inputs. The bug is public as [microsoft/TypeScript#64760](https://github.com/microsoft/TypeScript/issues/64760), and a fix is under review.\n\n- Rule\n- Declaration files the compiler writes must be valid TypeScript.\n- Smallest input\n- `export default 1.7976931348623159e308;`\n- Compiler output\n- `declare const _default = Infinity;`\n- Result\n- The same compiler rejects that file with error TS1254.\n- Also affects\n- TypeScript 6.0.3\n- Fix\n- Written with Claude Code from Breakspec’s fix request, verified by Breakspec, under review.\n\n## The bug\n\nA number too large for a double, like `1e400`, evaluates to `Infinity`. When the compiler writes a declaration file for a constant with that value, it writes `Infinity` as the initializer:\n\n``` js\n// m.ts\nexport const a = 1e400;\nexport const b = -1e400;\nexport class C {\n    static readonly e = 1e400;\n}\nexport default 1.7976931348623159e308;\njs\n// m.d.ts, as the compiler wrote it\nexport declare const a = Infinity;\nexport declare const b = -Infinity;\nexport declare class C {\n    static readonly e = Infinity;\n}\ndeclare const _default = Infinity;\nexport default _default;\n```\n\nThe compiler then rejects its own output. Each of those initializers is **error TS1254**: an ambient constant must be initialized with a string or numeric literal, and `Infinity` is a name, not a literal. A library that exports a constant like this ships declaration files that fail type-checking for its users, unless they skip checking library types.\n\n## It isn’t new\n\nTypeScript 6.0.3 writes the same initializers. We checked in the TypeScript Playground. The bug predates the move to the new compiler written in Go, and no existing TypeScript test covered it.\n\n## How Breakspec found it\n\n- We used the repository as it was on its main branch, unchanged.\n- We gave it one rule, on `CommandLine` , the compiler’s entry point: declaration files the compiler writes are valid TypeScript. The check compiles a program with declarations on, then compiles those declarations with the same compiler.\n- Breakspec ran the compiler in an isolated sandbox and broke the rule after 19 inputs. The smallest is one line, `export default 1.7976931348623159e308;` , just past the largest number a double can hold.\n\n## The fix, and how it was checked\n\nBreakspec turned the failure into a fix request, and Claude Code wrote the fix from it: a constant whose value is `Infinity` or `NaN` gets the type `number` instead of an initializer.\n\n``` js\n// m.d.ts, with the fix\nexport declare const a: number;\nexport declare const b: number;\nexport declare class C {\n    static readonly e: number;\n}\ndeclare const _default: number;\nexport default _default;\n```\n\n- Breakspec replayed the failing input against the fix, then tried 300 fresh inputs. None failed.\n- TypeScript’s own Go test suite passes: 64 packages, plus a new compiler test. Without the fix, that test records 6 TS1254 errors.\n- References to enum members with these values, like `E.A` , were already valid and are left alone.\n- The pull request says the fix was written with AI assistance, as TypeScript’s contribution guidelines ask, and a person is responsible for it in review.\n\n## The recording\n\nThe recording mixes live dashboard footage with explanation slides. The dashboard parts were recorded live on the real repository: approving the rules, the run that finds the bug, and the check of the fix. The slides show the fix itself, TypeScript’s test results and the commit. The two long waits are sped up, with an on-screen clock showing the real time.\n\n## What this shows\n\nThe TypeScript compiler has a large test suite, and it passed. The bug sat where no example test looked, and one rule about what must always be true found it. Breakspec does the same for the code your agents write: it works out what must hold, proves each failure, has your agent fix it and checks the fix.\n\n[Join the waitlist](https://docs.google.com/forms/d/e/1FAIpQLScI5ztjJ1qEnuP219Tq5y99Wr6cSrfv6aa6lHXuSPxEbgaz5Q/viewform)\n\nTypeScript is a trademark of Microsoft Corporation. Breakspec isn’t affiliated with or endorsed by Microsoft. The issue and pull request are public on GitHub; their status may have changed since this page was written.", "url": "https://wpnews.pro/news/one-rule-found-a-bug-that-typescripts-test-suite-missed", "canonical_source": "https://breakspec.com/typescript", "published_at": "2026-10-19 19:52:17+00:00", "updated_at": "2026-10-19 20:17:40.706973+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "ai-agents"], "entities": ["Breakspec", "Microsoft", "TypeScript", "Claude Code", "microsoft/TypeScript#64760"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/one-rule-found-a-bug-that-typescripts-test-suite-missed", "markdown": "https://wpnews.pro/news/one-rule-found-a-bug-that-typescripts-test-suite-missed.md", "text": "https://wpnews.pro/news/one-rule-found-a-bug-that-typescripts-test-suite-missed.txt", "jsonld": "https://wpnews.pro/news/one-rule-found-a-bug-that-typescripts-test-suite-missed.jsonld"}}