0
0
DenoHow-ToBeginner ยท 3 min read

How to Use deno check: Syntax, Example, and Tips

Use deno check to analyze your code for errors without executing it. Run deno check [file] in your terminal to perform a quick type and syntax check on your Deno scripts.
๐Ÿ“

Syntax

The basic syntax of deno check is simple and straightforward:

  • deno check [options] [files]

Here:

  • [files] is one or more file paths or URLs to check.
  • [options] are optional flags to customize the check behavior.

This command checks your code for type errors and syntax issues without running it.

bash
deno check [options] <file1> <file2> ...
๐Ÿ’ป

Example

This example shows how to use deno check on a TypeScript file named example.ts. It will report any type or syntax errors without running the code.

bash
echo "const greeting: string = 123;" > example.ts

deno check example.ts
Output
error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. const greeting: string = 123; ~~~ Found 1 error.
โš ๏ธ

Common Pitfalls

Some common mistakes when using deno check include:

  • Expecting deno check to run the code. It only checks types and syntax.
  • Not specifying files or using wrong paths, which results in no output.
  • Confusing deno check with deno run, which executes the code.

Always ensure your file paths are correct and remember deno check is for static analysis only.

bash
echo "console.log('Hello')" > hello.ts

deno check wrongpath.ts

# No output because file does not exist

deno run hello.ts
# This runs the code and prints 'Hello'
๐Ÿ“Š

Quick Reference

CommandDescription
deno check Check a file for type and syntax errors without running it
deno check --unstable Use unstable APIs during check
deno check --ignore=pattern Ignore files matching pattern
deno check --json Output errors in JSON format
โœ…

Key Takeaways

Use deno check to quickly find type and syntax errors without running code.
Always specify correct file paths to get meaningful results.
deno check does not execute code, unlike deno run.
You can use options like --json for machine-readable output.
It helps catch errors early during development for safer code.