microsoft / microsoft/TypeScript

RemoteNodeList inherited array methods throw this.view.getUint32 is not a function

Open
#63,838 1 comment 1 reaction 2 assignees Claimed by @andrewbranch View on GitHub
Needs Investigation
Dominant language
Go
Stars
111k
Forks
14.3k
PR merge metrics
PR metrics pending

Description

## Steps to reproduce

Using `@typescript/native-preview@7.0.0-dev.20260616.1` and Node `v24.11.1`:

1. Create a minimal project and install native-preview:

```sh
mkdir tsgo-remote-node-list-filter
cd tsgo-remote-node-list-filter
npm init -y
npm install @typescript/native-preview@7.0.0-dev.20260616.1
```

2. Save this as `repro.mjs`:

```js
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

import { API } from "@typescript/native-preview/unstable/sync";

const source = `interface A {}
interface B {}
`;

const directory = fs.mkdtempSync(path.join(os.tmpdir(), "tsgo-remote-node-list-filter-"));
fs.writeFileSync(
path.join(directory, "tsconfig.json"),
JSON.stringify(
{
compilerOptions: {
module: "NodeNext",
moduleResolution: "NodeNext",
skipLibCheck: true,
strict: true,
target: "ES2022",
},
files: ["index.ts"],
},
null,
2
)
);
fs.writeFileSync(path.join(directory, "index.ts"), source);

const api = new API({ cwd: directory });

try {
const project = api.updateSnapshot({ openProject: "tsconfig.json" }).getProjects()[0];
const sourceFile = project.program.getSourceFile("index.ts");

console.log(`sourceFile.statements.length = ${sourceFile.statements.length}`);
console.log(sourceFile.statements.filter(() => true).length);
} finally {
api.close();
}
```

3. Run:

```sh
node repro.mjs
```

## Actual behavior

`sourceFile.statements.length` works, but `sourceFile.statements.filter(() => true)` throws:

```
sourceFile.statements.length = 2
Calling sourceFile.statements.filter(() => true)...
TypeError: this.view.getUint32 is not a function
at RemoteNodeList.get data (node_modules/@typescript/native-preview/src/api/node/node.generated.ts:58:26)
at new RemoteNodeList (node_modules/@typescript/native-preview/src/api/node/node.generated.ts:70:28)
at RemoteNodeList.filter ()
at (repro.mjs:35:43)
at ModuleJob.run (node:internal/modules/esm/module_job:377:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:671:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)
```

`sourceFile.statements.map(...)`, `sourceFile.statements.flatMap(...)`, and other inherited array methods appear to have the same issue.

## Expected behavior

The native AST declarations expose `NodeArray` as extending `ReadonlyArray`, so standard array methods are available at compile time. I would expect those methods to work, or for `NodeArray` not to expose inherited array methods that are unsafe to call.

Workaround: `Array.from(sourceFile.statements).filter(() => true)` works.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.