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.tsOutput
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 checkto run the code. It only checks types and syntax. - Not specifying files or using wrong paths, which results in no output.
- Confusing
deno checkwithdeno 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
| Command | Description |
|---|---|
| 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.