Skip to content

fix(ts): enforce browser-only compatibility in fable-library-ts tsconfig#4563

Merged
MangelMaxime merged 1 commit into
mainfrom
repo-assist/fix-issue-4368-fable-library-ts-browser-compat-check-e40d2210715632df
Apr 26, 2026
Merged

fix(ts): enforce browser-only compatibility in fable-library-ts tsconfig#4563
MangelMaxime merged 1 commit into
mainfrom
repo-assist/fix-issue-4368-fable-library-ts-browser-compat-check-e40d2210715632df

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This is an automated draft PR from Repo Assist, created in response to maintainer request on #4368.

Problem

fable-library-ts was silently compiling with @types/node types available (because the monorepo has @types/node in its root node_modules). This masked browser-incompatible type usage: a user targeting browsers would see TypeScript errors for any direct Buffer references, even though the library code worked fine at runtime.

The issue was raised in #4368 and the Buffer usages in Encoding.ts were already fixed with the globalThis as any pattern. The remaining gap was no CI check to prevent future regressions.

Fix

Uncomment "types": [] in both tsconfig files:

  • src/fable-library-ts/tsconfig.json — used by IDEs when editing the source files
  • src/fable-library-ts/ts/tsconfig.json — copied to temp/fable-library-ts/ and used by tsc when building fable-library-js

With "types": [], TypeScript no longer auto-includes any @types/* package. Node.js-specific globals (Buffer, process, NodeJS.*, etc.) are excluded, simulating a browser-only environment.

What "types": [] does NOT affect:

  • Built-in TypeScript lib files (lib.es2020.d.ts, lib.dom.d.ts, etc.) — still included via "target": "es2020"
  • Browser APIs (TextEncoder, TextDecoder, fetch, crypto, setInterval, etc.) — still available
  • Explicit import type statements — still work

How the check is enforced

The tsc compilation step runs during ./build.sh fable-library --javascript (BuildFableLibraryJavaScript.PostFableBuildStage()), which uses the tsconfig from temp/fable-library-ts/. With "types": [] in place, any future accidental use of @types/node globals would fail this step with a clear TypeScript error.

Trade-offs

None expected. All Buffer usages already use (globalThis as any).Buffer and compile cleanly. The change makes an implicit guarantee explicit.

Closes #4368

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@51c8f6ad4357d2ecc06e47120031b3d75e80227d

@github-actions github-actions Bot added automation Automated changes bug repo-assist Created by Repo Assist TypeScript labels Apr 24, 2026
@MangelMaxime
MangelMaxime marked this pull request as ready for review April 24, 2026 20:51
@MangelMaxime

Copy link
Copy Markdown
Member

It does seems like the fix proposed could work.

If I comment out const g = globalThis as any; the compilation fails because Buffer is not found.

Let's see if the full CI passes

Add \"types\": [] to both tsconfig files (source + build copy) to
exclude all @types/* packages from automatic inclusion. This means
@types/node (Buffer, process, etc.) is no longer silently available
during tsc compilation, which catches browser-incompatible type usage.

All current Buffer references already use the `globalThis as any` escape
hatch, so the library compiles cleanly.

Closes #4368

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@MangelMaxime
MangelMaxime force-pushed the repo-assist/fix-issue-4368-fable-library-ts-browser-compat-check-e40d2210715632df branch from 158dc26 to b16cf2b Compare April 24, 2026 21:19
@MangelMaxime MangelMaxime changed the title [Repo Assist] fix(ts): enforce browser-only compatibility in fable-library-ts tsconfig fix(ts): enforce browser-only compatibility in fable-library-ts tsconfig Apr 26, 2026
@MangelMaxime
MangelMaxime merged commit 10c81c1 into main Apr 26, 2026
23 checks passed
@MangelMaxime
MangelMaxime deleted the repo-assist/fix-issue-4368-fable-library-ts-browser-compat-check-e40d2210715632df branch April 26, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Automated changes bug repo-assist Created by Repo Assist TypeScript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to test fable-library-ts ?

1 participant