Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper AsyncIterator polyfill #158

Open
yoursunny opened this issue Dec 12, 2024 · 1 comment
Open

Improper AsyncIterator polyfill #158

yoursunny opened this issue Dec 12, 2024 · 1 comment

Comments

@yoursunny
Copy link
Contributor

yoursunny commented Dec 12, 2024

@zenfs/core/dist/polyfills.d.ts improperly introduces [Symbol.asyncDispose] member into AsyncIterator type, breaking other code.
According to microsoft/TypeScript#59263 (comment) , [Symbol.asyncDispose] member is not part of the iterator protocol and does not belong in AsyncIterator type.
Instead, it exists on AsyncIteratorObject, renamed from BuiltinAsyncIterator in TypeScript 5.6.
This polyfill should be deleted in favor of referencing AsyncIteratorObject wherever [Symbol.asyncDispose] is needed.

package.json

{
  "private": true,
  "type": "module",
  "packageManager": "[email protected]+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c",
  "dependencies": {
    "@types/node": "^22.10.2",
    "@zenfs/core": "^1.6.8",
    "typescript": "~5.7.2"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "forceConsistentCasingInFileNames": true,
    "lib": [
      "ESNext"
    ],
    "module": "ES2022",
    "moduleResolution": "Bundler",
    "noEmitOnError": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "strict": true,
    "target": "ESNext",
    "types": [
      "node"
    ]
  },
  "include": [
    "main.ts"
  ],
  "exclude": [
    "**/node_modules"
  ]
}

main.ts

import { fs } from "@zenfs/core";

void fs;

export function f(): AsyncIterator<number> {
  let x = 0;
  return {
    next: async () => ({
      value: ++x,
    }),
  };
}

Command Line

./node_modules/.bin/tsc --noEmit

Error Message

main.ts:7:3 - error TS2741: Property '[Symbol.asyncDispose]' is missing in type '{ next: () => Promise<{ value: number; }>; }' but required in type 'AsyncIterator<number, any, any>'.

7   return {
    ~~~~~~

  node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.esnext.disposable.d.ts:40:5
    40     [Symbol.asyncDispose](): PromiseLike<void>;
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '[Symbol.asyncDispose]' is declared here.


Found 1 error in main.ts:7

This error does not occur if ZenFS is not imported.

@james-pre
Copy link
Member

james-pre commented Dec 12, 2024

This is a temporary mitigation due to a upstream incompatibility between readable-stream (using AsyncIterator) and @types/node (using NodeJS.AsyncIterator, which extends AsyncIteratorObject).

Once the upstream issue is fixed, this can be removed.

For more info, see DefinitelyTyped/DefinitelyTyped#71307.

If you know a better way to resolve the incompatibility before the upstream bug is fixed, please let me know.

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

No branches or pull requests

2 participants