docs: note that TypeScript applies the browser condition only on opt-in - #731
Merged
sroussey merged 1 commit intoAug 9, 2026
Conversation
Correct `exports` manifests pair each condition's `types` with the implementation beside it, but TypeScript's own condition set is ["import", "types"] under moduleResolution "bundler" and ["node", "import", "types"] under node16/nodenext — "browser" is in neither. A browser app therefore bundles dist/browser.js while tsc type-checks it against the node declarations unless the consumer sets customConditions: ["browser"]. Document that in the Conditional Exports section and in the multi-runtime resolution rules, and pin examples/web's opt-in with an assertion so deleting that one line fails loudly instead of silently reverting the example project to node declarations. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013oVdDSRMJeALBPLDQf3DgH
sroussey
merged commit Aug 9, 2026
fcda0c0
into
claude/wonderful-turing-rjtcnx-ai-types
9 of 10 checks passed
sroussey
deleted the
claude/optimistic-goldberg-9x9lby-browser-conditions
branch
August 9, 2026 19:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The manifest fix in #717 is complete and uniform — every condition branch now pairs its
typestarget with the implementation beside it, andExportTypesPairing.test.tsenforces that across all 163 branches. But a correct manifest is only half of the story.TypeScript's condition set is
["import", "types"]undermoduleResolution: "bundler"and["node", "import", "types"]undernode16/nodenext."browser"is in neither, and TypeScript only applies it when the consumer names it incustomConditions. So a plain bundler-mode consumer still bundlesdist/browser.jswhiletscresolves the outer"types"and type-checks it against the node declarations — no error anywhere, and symbols the browser bundle genuinely omits (_testOnly,OpenAI_ImageValidation,OpenAI_ModelSearchin@workglow/openai/ai) still autocomplete and compile, then readundefinedat runtime.The correct manifests do not fix that on their own; they move the drift from the manifest to the consumer's tsconfig. This PR says so where the rule is stated.
Changes
docs/technical/19-build-system.md— a paragraph in Conditional Exports stating the opt-in, with the tsconfig snippet andexamples/web/tsconfig.jsonas the in-repo example.docs/technical/18-multi-runtime-abstraction.md— one sentence on the same claim in the resolution-rules paragraph, linking to the section above.packages/test/src/test/util/ExportTypesPairing.test.ts— one assertion thatexamples/websetscustomConditions: ["browser"]. It is the repo's only browser-bundled TypeScript project and it imports packages carryingbrowserconditions (@workglow/util,@workglow/indexeddb/storage,@workglow/tf-mediapipe/ai); deleting that one line silently reverts it to node declarations with nothing failing. Verified by mutation — removing the line fails the test.Deliberately not added: a test that string-matches the doc prose. Nothing under
packages/testreadsdocs/, and such a test breaks on rewording without catching any real defect.Known follow-up (separate repo)
/home/user/builder'spackages/appis exactly the consumer described above:tsconfig.app.jsonismoduleResolution: "bundler"with nocustomConditions, and it imports@workglow/anthropic/ai,@workglow/deepseek/ai,@workglow/openai/aiand@workglow/tf-mediapipe/ai. It (and the six other bundler-mode tsconfigs there) should gain"customConditions": ["browser"]— a separate PR in a separate repo.Also out of scope: converging the node and browser barrels (dropping
_testOnlyfrom node barrels, exporting browser-safe modules from browser barrels). That is a public-API change across at least 8 provider packages and would obscure the manifest-correctness verification this branch already carries.Verification
bun scripts/test.ts util vitestbunx prettier --check(18, test file)bunx prettier --check docs/technical/19-build-system.mdbunx eslint …/ExportTypesPairing.test.ts --max-warnings 0bunx tsc --showConfig -p examples/web/tsconfig.jsoncustomConditionspresentOne deviation from the plan:
tsconfig.jsonis JSONC (examples/web/tsconfig.jsoncarries/* Bundler mode */comments), so a bareJSON.parsethrows. The test strips comments first via a small local helper.Generated by Claude Code