I've got a strange issue with TypeScript when trying to use the readline to create an interface reading the console window. From what I can tell, process.stdin returns a ReadStream whilst createInterface is expecting a ReadableStream but I'm not sure how to convert them. When I try to create an interface with readline.createInterface, TypeScript throws the following error:
No overload matches this call.
Overload 1 of 2, '(input: ReadableStream, output?: WritableStream | undefined, completer?: Completer | AsyncCompleter | undefined, terminal?: boolean | undefined): Interface', gave the following error.
Object literal may only specify known properties, and 'input' does not exist in type 'ReadableStream'.
import * as readline from 'readline';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: "> "
});
rl.on('line', (line) => {
console.log(`got ${line}`);
rl.prompt();
});
rl.prompt();
TypeScript Version: 5.2.2 Node.js Version: 18.20.4 @types/node Version: 22.5.2
I tried casting process.stdin to NodeJS.ReadableStream, made sure my tsconfig.json was set to expect node, but the same issue occurs. I've even tried updating @types/node to see if it's something to do with that to no avail. Any help would be amazing!
process.stdin instanceof stream.Readableis true. But you are using the other overloadcreateInterface(options: ReadLineOptions): Interface, and I wonder why this does not show up in the error message.