2

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!

3
  • process.stdin instanceof stream.Readable is true. But you are using the other overload createInterface(options: ReadLineOptions): Interface, and I wonder why this does not show up in the error message. Commented Sep 1, 2024 at 13:39
  • @HeikoTheißen oh I see, sorry, how do I swap the overload, I’m rather new to TS Commented Sep 1, 2024 at 14:11
  • TS should find the right overload automatically. Don't know why this does not work here. Commented Sep 1, 2024 at 14:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.