DenoDDeno
Powered by
rsdoielR
Denoβ€’14mo agoβ€’
3 replies
rsdoiel

In Deno 2.1.7 I stumbled on Deno.Stdin, Deno.FsFile but using these types fails to pass check

I can "run" the following code it doesn't pass check or compile. What is the right way to approach this?

(file is named foo.ts).
async function main () {
    let input: Stdin | FsFile;
    let decoder = new TextDecoder();
    console.log("Reading from helloworld.txt");
    // Try to read a named text file
    input = await Deno.open("helloworld.txt");
    for await(const chunk of input.readable) {
        console.log(decoder.decode(chunk));
    }
    // Now try to read from standard input
    console.log("Type in some text and press Ctrl-C to exit");
    input = Deno.stdin;
    for await(const chunk of input.readable) {
        console.log(decoder.decode(chunk));
    }        
}

if (import.meta.main) main();
async function main () {
    let input: Stdin | FsFile;
    let decoder = new TextDecoder();
    console.log("Reading from helloworld.txt");
    // Try to read a named text file
    input = await Deno.open("helloworld.txt");
    for await(const chunk of input.readable) {
        console.log(decoder.decode(chunk));
    }
    // Now try to read from standard input
    console.log("Type in some text and press Ctrl-C to exit");
    input = Deno.stdin;
    for await(const chunk of input.readable) {
        console.log(decoder.decode(chunk));
    }        
}

if (import.meta.main) main();


Running
deno run --allow-read foo.ts
deno run --allow-read foo.ts
works fine as does running the main function interactively in the REPL. On the other hand
deno check foo.ts
deno check foo.ts
returns the following message. How should I be import
Stdin
Stdin
ad
FsFile
FsFile
to allow it to be compiled?

Check file:///C:/Users/rsdoi/Sandbox/Writing/Articles/Deno/stdin_fsfile.ts
error: TS2304 [ERROR]: Cannot find name 'Stdin'.
        let input: Stdin | FsFile;
                   ~~~~~
    at file:///C:/Users/rsdoi/Sandbox/Writing/Articles/Deno/stdin_fsfile.ts:2:13

TS2552 [ERROR]: Cannot find name 'FsFile'. Did you mean 'File'?
        let input: Stdin | FsFile;
                           ~~~~~~
    at file:///C:/Users/rsdoi/Sandbox/Writing/Articles/Deno/stdin_fsfile.ts:2:21

    'File' is declared here.
    declare var File: {
                ~~~~
        at asset:///lib.deno.web.d.ts:622:13

Found 2 errors.
Check file:///C:/Users/rsdoi/Sandbox/Writing/Articles/Deno/stdin_fsfile.ts
error: TS2304 [ERROR]: Cannot find name 'Stdin'.
        let input: Stdin | FsFile;
                   ~~~~~
    at file:///C:/Users/rsdoi/Sandbox/Writing/Articles/Deno/stdin_fsfile.ts:2:13

TS2552 [ERROR]: Cannot find name 'FsFile'. Did you mean 'File'?
        let input: Stdin | FsFile;
                           ~~~~~~
    at file:///C:/Users/rsdoi/Sandbox/Writing/Articles/Deno/stdin_fsfile.ts:2:21

    'File' is declared here.
    declare var File: {
                ~~~~
        at asset:///lib.deno.web.d.ts:622:13

Found 2 errors.
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

`.read()` method in `Deno.Conn` or `Deno.FsFile` in Deno 2.0
DavidDDavid / help
3y ago
Using `Deno.FsFile.prototype.readable` with `Response`
csjhCcsjh / help
2y ago
Deno.stdin raw map?
DNADDNA / help
2y ago
DENO_FUTURE=1 / Deno 2 in deno subhosting
theswerdTtheswerd / help
2y ago