Closed gaeulbyul closed 1 year ago
You can get a wanted error from TypeScript by running deno check your_script.ts
.
$ cat script.ts
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: script.ts
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ function invalid() {
2 │ await Promise.resolve(true)
3 │ }
4 │
5 │ invalid()
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
$ deno check script.ts
Check file:///private/tmp/script.ts
error: TS1308 [ERROR]: 'await' expressions are only allowed within async functions and at the top levels of modules.
await Promise.resolve(true)
~~~~~
at file:///private/tmp/script.ts:2:3
TS1356 [ERROR]: Did you mean to mark this function as 'async'?
function invalid() {
~~~~~~~
at file:///private/tmp/script.ts:1:10
Basically deno_lint attempts to discover possibly problematic pieces of code that TypeScript is not covering. So putting await
in non-async functions is what TypeScript is responsible for, not deno_lint.
This will also fail at runtime:
> deno run main.js
error: Uncaught SyntaxError: Unexpected reserved word
await Promise.resolve(true)
^
at <anonymous> (file:///V:/deno_lint/main.js:2:3)
Lint Name
SyntaxError?
Code Snippet
Expected Result
It should report as syntax error
Actual Result
Deno doesn't find any problem with that code.
Additional Info
Version