Skip to content

bun-types: dedupe alias enum keys in FFI type maps#29193

Open
robobun wants to merge 4 commits intomainfrom
farm/11b838b5/ffi-dedupe-alias-keys
Open

bun-types: dedupe alias enum keys in FFI type maps#29193
robobun wants to merge 4 commits intomainfrom
farm/11b838b5/ffi-dedupe-alias-keys

Conversation

@robobun
Copy link
Copy Markdown
Collaborator

@robobun robobun commented Apr 11, 2026

What

FFITypeToArgsType / FFITypeToReturnsType in packages/bun-types/ffi.d.ts used to list every FFIType enum alias (e.g. i8 / int8_t, pointer / ptr, int / int32_t) as a separate computed property key. Because the alias members share the same numeric value, tsc tolerated the identical-value duplicates but tsgo (TypeScript native preview) rejects every pair with TS2300: Duplicate identifier, which breaks projects that type-check with tsgo / @effect/tsgo.

Repro

npm i -D @typescript/native-preview bun-types@1.3.12
echo 'export {};' > index.ts
npx tsgo --noEmit -p tsconfig.json
# ffi.d.ts(347,5): error TS2300: Duplicate identifier '[FFIType.int8_t]'.
# ffi.d.ts(349,5): error TS2300: Duplicate identifier '[FFIType.uint8_t]'.
# ... ~40 more lines

Root cause

TypeScript resolves [FFIType.i8] and [FFIType.int8_t] to the same numeric literal key 1. With two value-identical duplicate keys in one interface, old TS emits a warning but accepts it; tsgo emits TS2300 and fails the build.

Fix

Keep only the canonical enum members (int8_t, uint8_t, int16_t, …, ptr, double, float) in both interfaces. Alias lookups continue to resolve correctly — FFITypeToArgsType[FFIType.i8] still evaluates to number because it indexes by the same numeric key as FFIType.int8_t. The existing test/integration/bun-types/fixture/ffi.ts fixture already exercises alias lookups (FFIType.i8, FFIType.u8, FFIType.pointer, FFIType.int, etc.) with expectTypeEquals and still passes.

FFITypeStringToType (keyed by unique strings, not enum members) is unaffected and kept as-is.

Verification

  • bun test test/regression/issue/29191.test.ts — new regression test parses ffi.d.ts, resolves every [FFIType.*] key inside the two interfaces to its enum value, and asserts none collide.
  • bun test test/integration/bun-types/bun-types.test.ts — all 11 existing bun-types integration tests pass, including the FFI alias lookup fixture.
  • tsgo --noEmit on the patched ffi.d.ts — no more TS2300 errors.

Fixes #29191

The FFIType enum declares several alias members that share the same
numeric value (i8 == int8_t == 1, pointer == ptr == 12, int == int32_t
== 5, etc.). FFITypeToArgsType and FFITypeToReturnsType used to list
every alias as its own computed property key. tsc tolerated the
identical-value duplicates, but tsgo (TypeScript native preview) flags
each alias pair as a duplicate identifier (TS2300) and fails the build.

Keep the canonical names only. Lookups through aliases still resolve
correctly because they map to the same numeric key as the canonical
member that remains in the interface.

Fixes #29191
@robobun robobun requested a review from alii as a code owner April 11, 2026 19:28
@robobun
Copy link
Copy Markdown
Collaborator Author

robobun commented Apr 11, 2026

Updated 2:48 PM PT - Apr 11th, 2026

❌ Your commit 75744734 has 2 failures in Build #45182 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 29193

That installs a local version of the PR into your bun-29193 executable, so you can run:

bun-29193 --bun

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

Warning

Rate limit exceeded

@robobun has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 37 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 4 minutes and 37 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 281df80d-e3b0-4fe5-b278-d610a0c8d8d1

📥 Commits

Reviewing files that changed from the base of the PR and between 5ee9e31 and 7574473.

📒 Files selected for processing (1)
  • test/regression/issue/29191.test.ts

Walkthrough

Removed alias computed-property mappings from internal FFI type-mapping interfaces to avoid duplicate computed keys and added a regression test that parses ffi.d.ts to ensure no duplicate computed keys or missing enum references.

Changes

Cohort / File(s) Summary
FFI Type Declarations
packages/bun-types/ffi.d.ts
Deleted computed-property entries for alias enum members (i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, pointer) from FFITypeToArgsType and FFITypeToReturnsType, kept only canonical members (int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, float, double, ptr), and added a comment explaining the rationale to avoid duplicate computed-property keys.
Regression Testing
test/regression/issue/29191.test.ts
Added a test that loads packages/bun-types/ffi.d.ts, parses the FFIType enum and the FFITypeToArgsType/FFITypeToReturnsType interfaces, asserts the computed-property lists are non-empty, checks no numeric enum value is referenced more than once across computed keys, and verifies alias pairs resolve to identical numeric values.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly and concisely describes the main change: deduplicating alias enum keys in FFI type maps.
Description check ✅ Passed Description covers both required template sections: explains what the PR does (removes duplicate enum alias keys from FFI type maps) and how code was verified (regression test, integration tests, tsgo verification).
Linked Issues check ✅ Passed Changes fully address #29191: removed duplicate computed keys from FFITypeToArgsType and FFITypeToReturnsType, preserving alias lookup behavior, and added regression test to assert no key collisions.
Out of Scope Changes check ✅ Passed All changes are in-scope: modifications to ffi.d.ts interfaces target the duplicate key issue, and the regression test directly validates the fix without introducing unrelated changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/regression/issue/29191.test.ts`:
- Around line 3-9: Trim the verbose bug-history prose in the test header and
leave only the single-line GitHub issue URL comment; specifically remove the
multi-line explanation about `bun-types/ffi.d.ts`, alias enum members, and the
`tsgo` duplicate identifier note, and instead move any necessary context into
the test name or assertions that reference `FFITypeToArgsType`,
`FFITypeToReturnsType`, and `FFIType.*` computed keys so the test file contains
a concise header and the explanatory details live in the test metadata or
assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c498f986-e12b-49a2-8aeb-984a860f8bdb

📥 Commits

Reviewing files that changed from the base of the PR and between 4b1d889 and 2ef36de.

📒 Files selected for processing (2)
  • packages/bun-types/ffi.d.ts
  • test/regression/issue/29191.test.ts

Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — mechanical dedup of alias enum keys with correct reasoning and adequate test coverage.

Extended reasoning...

Overview

The PR modifies two files: (removes ~25 duplicate computed property keys from and ) and adds a new regression test .

Correctness

The fix is semantically correct. and both resolve to numeric value ; removing the alias from the interface does not change lookup behavior — still resolves to which maps to . The interface (string-keyed, not enum-keyed) is correctly left untouched.

Security Risks

None. This is a pure TypeScript declaration file change with no runtime code.

Level of Scrutiny

Low scrutiny needed. The change is mechanical (delete duplicate lines), the reasoning is sound, and the existing integration test fixture () already exercises alias lookups with . The one bug found is a nit about the sanity test not guarding against an empty parse result; the more important duplicate-detection test has proper guards and would throw on unknown enum members.

Other Factors

The inline comment already flags the nit about the sanity test's false-green potential. No CODEOWNER files appear to cover this path, the change is small and self-contained, and the PR description includes a clear repro and verification steps.

Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — my prior concern about false-green sanity tests was addressed in the latest commit.

Extended reasoning...

Overview

This PR modifies two files: packages/bun-types/ffi.d.ts removes duplicate computed-property keys (alias enum members) from FFITypeToArgsType and FFITypeToReturnsType, and test/regression/issue/29191.test.ts adds a regression test that parses the declaration file and asserts no numeric enum value is used as a computed key more than once.

Security risks

None. This is a purely additive type-declaration change with no runtime behaviour; the regression test only reads files on disk.

Level of scrutiny

Low. The fix is mechanically correct: enum aliases share the same numeric value, so removing the redundant computed keys has no effect on the resolved type. The TypeScript specification guarantees that FFITypeToArgsType[FFIType.i8] still resolves to number because FFIType.i8 === FFIType.int8_t === 1. The integration fixture (test/integration/bun-types/fixture/ffi.ts) already exercises alias lookups with expectTypeEquals, confirming the change is non-breaking.

Other factors

My earlier inline comment flagging the false-green risk in the sanity test (if parseEnum returned an empty Map) was addressed in commit 7574473, which added the expect(enumValues.size).toBeGreaterThan(0) guard and strengthened pair assertions to use expect.any(Number) before the toBe comparison. The coderabbitai nitpick about verbose header comments was also addressed in an earlier commit. No outstanding reviewer comments remain.

@robobun
Copy link
Copy Markdown
Collaborator Author

robobun commented Apr 11, 2026

CI test-bun failures on 3 aarch64 runners (darwin-13/14, ubuntu-25.04) — unrelated to this change. The fix is .d.ts-only and cannot produce runtime test failures targeting specific aarch64 runners while every x64 test-bun job passes and 5 of 8 aarch64 test-bun jobs also pass (linux-aarch64, linux-aarch64-musl, debian-13-aarch64, alpine-3.23-aarch64, windows-11-aarch64). Needs a maintainer retry — the Buildkite logs are auth-gated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bun-types@1.3.12: duplicate computed keys in bun:ffi break tsgo / TypeScript native preview

1 participant