Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: Fix TypeScript compilation in a Node.js environment#256

Merged
kou merged 1 commit intoapache:mainfrom
alecgibson:fix-node-types
Sep 11, 2025
Merged

fix: Fix TypeScript compilation in a Node.js environment#256
kou merged 1 commit intoapache:mainfrom
alecgibson:fix-node-types

Conversation

@alecgibson
Copy link
Contributor

Fixes #45

This library runs in modern browsers, but is also intended for use in maintained versions of Node.js, which means that the TypeScript types cannot assume "lib": ["DOM"].

This change removes this lib, and updates the types to compile.

Given that this library runs in the browser, it feels strange to import types from node, but this is no worse than the current situation, which already contains imports from node.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes TypeScript compilation issues when using the Apache Arrow JavaScript library in Node.js environments by removing DOM types dependency and updating type definitions.

  • Removes "DOM" from the TypeScript lib configuration to avoid browser-specific type assumptions
  • Updates type definitions to use Node.js stream types instead of DOM-specific types
  • Replaces BufferSource type with a more generic parameter type for TextDecoder.decode()

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tsconfig/tsconfig.base.json Removes "DOM" from TypeScript lib array to support Node.js environments
src/util/utf8.ts Replaces DOM-specific BufferSource type with generic parameter type
src/util/compat.ts Adds import for Node.js UnderlyingSink type
src/util/buffer.ts Adds import for Node.js ReadableStreamReadResult type
src/io/interfaces.ts Adds import for Node.js StreamPipeOptions type
src/io/adapters.ts Adds import for Node.js ReadableStreamReadValueResult type

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

src/util/utf8.ts Outdated
const decoder = new TextDecoder('utf-8');
/** @ignore */
export const decodeUtf8 = (buffer?: BufferSource) => decoder.decode(buffer);
export const decodeUtf8 = (buffer?: Parameters<InstanceType<typeof TextDecoder>['decode']>[0]) => decoder.decode(buffer);
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

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

The type Parameters<InstanceType<typeof TextDecoder>['decode']>[0] is overly complex and hard to read. Consider extracting this to a type alias or using a simpler approach like ArrayBuffer | ArrayBufferView | null | undefined which matches the actual parameter type.

Suggested change
export const decodeUtf8 = (buffer?: Parameters<InstanceType<typeof TextDecoder>['decode']>[0]) => decoder.decode(buffer);
export const decodeUtf8 = (buffer?: ArrayBuffer | ArrayBufferView | null | undefined) => decoder.decode(buffer);

Copilot uses AI. Check for mistakes.
@kou kou requested review from domoritz and trxcllnt August 22, 2025 06:11
src/util/utf8.ts Outdated
const decoder = new TextDecoder('utf-8');
/** @ignore */
export const decodeUtf8 = (buffer?: BufferSource) => decoder.decode(buffer);
export const decodeUtf8 = (buffer?: Parameters<InstanceType<typeof TextDecoder>['decode']>[0]) => decoder.decode(buffer);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is also an option?

Suggested change
export const decodeUtf8 = (buffer?: Parameters<InstanceType<typeof TextDecoder>['decode']>[0]) => decoder.decode(buffer);
export const decodeUtf8 = decoder.decode.bind(decoder);

Fixes apache#45

This library runs in modern browsers, but is also intended for use in
maintained versions of Node.js, which means that the TypeScript types
cannot assume `"lib": ["DOM"]`.

This change removes this `lib`, and updates the types to compile.

Given that this library runs in the browser, it feels strange to import
types from `node`, but this is no worse than the current situation,
which already contains imports from `node`.
@kou kou changed the title Fix TypeScript compilation in a Node.js environment fix: Fix TypeScript compilation in a Node.js environment Sep 11, 2025
@kou kou merged commit 42837f6 into apache:main Sep 11, 2025
11 checks passed
@alecgibson alecgibson deleted the fix-node-types branch September 11, 2025 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JS] Apache Arrow does not compile with Typescript when types are checked

4 participants