Repository navigation
Conversation
…nd an alias of `true | false` as `boolean` A constant that only a type names is declared in the typed file with the text that the type printer has for its type. The printer says `Infinity` for the type of `1e999`, which is a value and no type, and it names the alias of a `true | false` union, which can be another type where the constant is declared.
|
Status: ready for review at 73a0a8a. Reproduced on release and debug builds of main 98cda0d. A package whose With this branch the typed file has PR: #48485 |
|
Updated 11:31 AM PT - Nov 10th, 2026
✅ @robobun, your commit 73a0a8a51a6c3b41b0358f310a2e637606a59d35 passed in 🧪 To try this PR locally: bunx bun-pr 48485That installs a local version of the PR into your bun-48485 --bun |
|
No actionable comments were generated in the recent review. WalkthroughThe constant type collection path now formats qualifying literal and intrinsic types with a new helper. Added tests check generated declaration output for boolean values, non-finite numeric literals, retained literal types, and library builds. ChangesDeclaration constant types
Possibly related PRs
Suggested reviewers: Merge Risk:
|
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Beyond the inline finding, I also checked two edges of text_that_names_nothing: the boolean branch cannot widen a bare true/false constant, because TypeFlags::BOOLEAN is only set on the two-member true | false union (src/sema/types.rs flags computation) while a lone literal carries BOOLEAN_LITERAL; and the non-finite branch cannot catch NaN, since no source literal produces a NaN literal type (NaN itself types as number). I did not build or run the two new tests.
Extended reasoning...
The change extracts the declare const text selection in src/sema/driver/typed_files.rs into a helper and adds two overrides (boolean for an aliased true | false, number for a non-finite number literal), with tests in test/bundler/bun-build-api-dts.test.ts and test/cli/compile/compile-library.test.ts. It touches no security-sensitive surface. The one inline finding is the as const tuple/object sibling case the PR leaves as a test.todo, so a human should decide whether that scope is acceptable.
Problem
bun build --dtswithconst big = 1e999that only a type names:warn: the .aot.ts files that --aot compiles a package from are left out: they have type errors, the first at index.aot.ts:3:20: TS2749: 'Infinity' refers to a value, but is being used as a type here. Did you mean 'typeof Infinity'?true | falseis declared by its name, which can be another type in the bundle:TS2322: Type 'boolean' is not assignable to type 'Flag'.module_types(src/sema/driver/typed_files.rs:4396) takes the text of the declaration from the type printer.Fix
number, andboolean.test/bundler/bun-build-api-dts.test.ts,test/cli/compile/compile-library.test.ts. 2 new tests fail on main.Background
index.aot.tsisindex.jswith the source types put back. One type error leaves out all of them.typeof big) is not in the bundle. The typed file declares it:declare const big: T;.1e999. The bundle hasInfinityfor the value, which does not fit it.Downsides
typeof bigisnumberin the typed file, and the type of1e999in the sources.index.d.tssaysnumber.test.todorow).Notes
Repros (each is a package with
"strict": true, built withbun build ./src/index.ts --dts --outdir out. Main exits 0, prints the warning and writesindex.jsandindex.d.tsonly.)Main writes
declare const big: Infinity;into the typed file (TS2749).-1e999givesdeclare const small: -Infinity;andTS1110: Type expected.This branch writesdeclare const big: number;.Main writes
declare const on: Flag;, andFlagis the type ofsrc/index.tsthere:index.aot.ts:7:3: TS2322: Type 'boolean' is not assignable to type 'Flag'.This branch writesdeclare const on: boolean;.The change
text_that_names_nothinghas the test that main has (the type is a literal or a keyword, and no member of an enum) and takes the text from the printer, but for two types:true | falseunion. It is one type with and without an alias, and the printer names the alias that the source has.Infinityor-Infinity, which are values.1e999is a literal type that TypeScript accepts (declare const big: 1e999). It is not the text here because the bundle hasInfinityfor the value, soreturn Infinityinbiggest()does not type check against it.index.d.tsof the same build hasdeclare const big = Infinity;, which isnumberfor whoever reads it.Measured (main 98cda0d and this branch)
sizeof the release binary: text 142,830,298 bytes on main, 142,830,554 on this branch. The file is 143,018,256 and 143,022,352 bytes.module_typesand inadd_types, counted under gdb on debug builds, for a module with 300 functions and 100 constants that only a type names: 6,251 and 23,545 on both.true,false,null,undefined, a template, a unique symbol) in one module:index.aot.tsis the same bytes on both.Not fixed
const pair = [1e999, 1] as constthat only a type names:declare const pair: readonly [Infinity, 1];(TS2749), as on main. The text for a constant whose type is no literal and no keyword is the one thatindex.d.tshas.index.aot.tsthat an earlier build wrote into the sameoutdir. That is main too.Suites run (debug ASAN build of this branch)
test/bundler/bun-build-api-dts.test.ts: 8 pass, 1 todo, and "writes the bundle, its declaration files and the bundle with its types kept to outdir" runs into the 5 s limit in a debug build here (5.0 s, and 5.2 s on a debug build of main).test/cli/compile/compile-library.test.tswith a longer time limit: the new test passes. On a debug build of main the two new tests fail.Origin
This was a part of #48267. A review of #48267 asked for the parts that need no React Compiler as a PR of their own. #48466 has the enum part of those, so this PR has the constants alone.
no test proof · iteration 0 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/cli/compile/compile-library.test.ts