Add TextEncoder and TextDecoder TypeScript type declarations#56326
Add TextEncoder and TextDecoder TypeScript type declarations#56326deyaaeldeen wants to merge 1 commit intofacebook:mainfrom
Conversation
|
Hi @deyaaeldeen! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
d0cc078 to
35b96b6
Compare
Both TextEncoder and TextDecoder are now natively available in Hermes: - TextEncoder since React Native 0.74 (facebook/hermes#948) - TextDecoder since React Native 0.85 (facebook/hermes#1855) This adds global type declarations matching the Hermes implementation, following the same interface + var pattern used by all other Web API types in this file. Closes facebook#56325 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
35b96b6 to
4b0dac3
Compare
Hey! Both
TextEncoderandTextDecoderare now natively available in Hermes:TextEncoderlanded in Hermes for RN 0.74 (using TextEncoder with hermes hermes#948)TextDecoderlanded in Dec 2025 (Add support for TextDecoder hermes#1855), should ship with RN 0.85But neither is declared in React Native's TypeScript globals (
src/types/globals.d.ts), so TypeScript users have to either cast throughany, pull inlib: ["dom"], or add their own declarations to use these APIs without type errors.This adds type declarations for both APIs to
globals.d.ts, following the sameinterface+varpattern used by all other Web API types in the file. The types match what Hermes actually implements:TextEncoder:
encoding(always"utf-8")encode(input?): Uint8ArrayencodeInto(input, destination): { read, written }TextDecoder:
{ fatal?, ignoreBOM? }optionsencoding,fatal,ignoreBOMgettersdecode(input?, { stream? }): stringTest Plan
Added type tests in
packages/react-native/types/__typetests__/globals.tsxcovering:TextEncoder: constructor,encode(),encode(string),encodeInto(), andencodingliteral typeTextDecoder: constructor (no args, with label, with options),decode()fromUint8Array/ArrayBuffer/empty,decodewith{ stream }option, and all three getters (encoding,fatal,ignoreBOM)Ran
tsc --noEmitagainst the type tests — no new errors introduced.Changelog:
[General] [Added] - Add TypeScript type declarations for TextEncoder and TextDecoder
Closes #56325