bun
bun copied to clipboard
Type 'ReadableStream<any>' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.ts(2504)
What is the type of issue?
Example code is not working
What is the issue?
const stream = new ReadableStream({
start(controller) {
controller.enqueue('hello')
controller.enqueue('world')
controller.close()
},
})
//! Type 'ReadableStream<any>' must have a '[Symbol.asyncIterator]()' method
//! that returns an async iterator.ts(2504)
for await (const chunk of stream) {
console.log(chunk)
// => "hello"
// => "world"
}
maybe tsconfig.json is wrong?
// tsconfig.json
{
"compilerOptions": {
"target": "ESNext",
"jsx": "react-jsx",
// Enable latest features
"lib": ["ESNext", "DOM"],
"moduleDetection": "force",
"module": "ESNext",
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"allowJs": true,
// Best practices
"strict": true,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true,
// Some stricter flags
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true
}
}
Where did you find it?
https://bun.sh/docs/api/streams