bun-types: dedupe alias enum keys in FFI type maps#29193
bun-types: dedupe alias enum keys in FFI type maps#29193
Conversation
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
|
Updated 2:48 PM PT - Apr 11th, 2026
❌ Your commit
🧪 To try this PR locally: bunx bun-pr 29193That installs a local version of the PR into your bun-29193 --bun |
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughRemoved alias computed-property mappings from internal FFI type-mapping interfaces to avoid duplicate computed keys and added a regression test that parses Changes
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
packages/bun-types/ffi.d.tstest/regression/issue/29191.test.ts
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
CI test-bun failures on 3 aarch64 runners (darwin-13/14, ubuntu-25.04) — unrelated to this change. The fix is |
What
FFITypeToArgsType/FFITypeToReturnsTypeinpackages/bun-types/ffi.d.tsused to list everyFFITypeenum 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,tsctolerated the identical-value duplicates buttsgo(TypeScript native preview) rejects every pair withTS2300: Duplicate identifier, which breaks projects that type-check withtsgo/@effect/tsgo.Repro
Root cause
TypeScript resolves
[FFIType.i8]and[FFIType.int8_t]to the same numeric literal key1. With two value-identical duplicate keys in one interface, old TS emits a warning but accepts it;tsgoemitsTS2300and 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 tonumberbecause it indexes by the same numeric key asFFIType.int8_t. The existingtest/integration/bun-types/fixture/ffi.tsfixture already exercises alias lookups (FFIType.i8,FFIType.u8,FFIType.pointer,FFIType.int, etc.) withexpectTypeEqualsand 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 parsesffi.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 --noEmiton the patchedffi.d.ts— no more TS2300 errors.Fixes #29191