Jens-G opened a new pull request, #3902:
URL: https://github.com/apache/thrift/pull/3902
`ts_get_type()` emitted `Buffer` for every `binary` field, in both the node
and the browser
TypeScript output. The browser has no `Buffer`, and the browser library does
not use one:
- `lib/js/src/thrift.js`: `readBinary()` returns `atob(r.value)` — a string.
- `lib/js/src/thrift.js`: `writeBinary(binary)` accepts a string or a
`Uint8Array`.
- `lib/ts/thrift.d.ts`, the hand-written declaration for this binding,
already says
`writeBinary(str: string): void`.
So the generated declarations contradicted the library's own.
`lib/ts/test/test.ts` is written
against the real API and passes a string, which made it uncompilable against
its own generated
types — the test was right and the generator was wrong.
The fix gates the `Buffer` on `gen_node_`. Binary stays `Buffer` for
`js:node,ts` and becomes
`string` for `js:ts`.
Not a union: `string | Uint8Array` would have been wrong in the container
case, because
`ts_get_type(etype) + "[]"` renders a union as `string | Uint8Array[]`,
which TypeScript parses
as `string | (Uint8Array[])`. `string` also matches what `readBinary()`
actually returns and what
`thrift.d.ts` already declares.
Verified with a probe carrying `binary` in every position — plain field,
list element, map value,
set element, typedef, optional field, service argument, service return and
callback:
- `js:ts` now emits `string`, `string[]`, `{ [k: string]: string; }`
throughout.
- `js:node,ts` is unchanged, `Buffer` everywhere.
- `make -C lib/ts check`'s TypeScript step (`shell:BuildTS`) completes
instead of failing with
`TS2345: Argument of type 'string' is not assignable to parameter of type
'Buffer'`.
`clang-format -style=file` leaves the changed lines untouched.
The lib/ts test still does not run to completion — THRIFT-6318 is the next
blocker — and
THRIFT-6319 tracks the fact that nothing in the build or in CI runs it at
all.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]