deno

What is the deno equivalent of node --check


In node there is a --check option to check if code is valid for execution without actually running it if valid. I have been looking for an equivalent in deno (deno help, deno run help, deno lint help)

The closest i can figure out is deno lint, but it will happily lint the following typescript code (in test.ts), which deno run subsequently refuses to run (obviously).

What is the canonical deno "dry run"?

test.ts:

const message = "hello!";
message();

Solution

  • check if code is valid for execution

    "dry run"

    These concepts don't exist. I think what you want is to have your TypeScript code analyzed using static type-checking (without actually running the module). This is called compilation and the Deno subcommand you want in this case is check:

    deno check module.ts
    

    Using your example test.ts:

    $ deno check test.ts
    Check file:///tmp/test.ts
    TS2349 [ERROR]: This expression is not callable.
      Type 'String' has no call signatures.
    message();
    ~~~~~~~
        at file:///tmp/test.ts:2:1
    
    error: Type checking failed.