Skip to main content
On this page

deno check

deno check 会对你的 TypeScript(或 JavaScript)代码进行类型检查,而不会运行它。 这在 CI 流水线中或部署前很有用,可以尽早发现类型错误。 有关 Deno 中的 TypeScript 的更多信息,请参阅 TypeScript 指南。

基本用法 Jump to heading

>_
deno check main.ts

检查多个文件:

>_
deno check src/server.ts src/utils.ts

对远程模块进行类型检查 Jump to heading

默认情况下,只会对本地模块进行类型检查。使用 --all 也可以对 远程依赖进行类型检查:

>_
deno check --all main.ts

对 JavaScript 文件进行类型检查 Jump to heading

如果你有一个 JavaScript 项目,并且想在不为每个文件添加 // @ts-check 的情况下对其进行类型检查,请使用 --check-js 标志:

>_
deno check --check-js main.js

在 CI 中使用 Jump to heading

如果存在类型错误,deno check 会以非零状态码退出,因此它适合用于 CI 流水线:

>_
deno check main.ts && echo "Types OK"

请注意,deno testdeno bench 已经默认执行类型检查,因此如果你已经在运行测试,就不需要单独再执行 deno check 步骤。 当你想在不运行任何内容的情况下进行类型检查时,请使用 deno check——例如,作为 CI 中一个快速的前置步骤:

>_
deno check main.ts
deno lint
deno test
Command line usage:
deno check [OPTIONS] [file]...

Download and type-check without execution.

deno check jsr:@std/http/file-server

Unless --reload is specified, this command will not re-download already cached dependencies

Dependency management options Jump to heading

--frozen<BOOLEAN>optional
Jump to heading

Error out if lockfile is out of date.

Load import map file from local file or remote URL.

--lock<FILE>optional
Jump to heading

Check the specified lock file. (If value is not provided, defaults to "./deno.lock").

Disable auto discovery of the lock file.

Do not resolve npm modules.

--no-remote
Jump to heading

Do not resolve remote modules.

--node-modules-dir<MODE>optional
Jump to heading

Sets the node modules management mode for npm packages.

--reload, -r<CACHE_BLOCKLIST>optional
Jump to heading

Reload source code cache (recompile TypeScript) no value Reload everything jsr:@std/http/file-server,jsr:@std/assert/assert-equals Reloads specific modules npm: Reload all npm modules npm:chalk Reload specific npm module.

--vendor<vendor>optional
Jump to heading

Toggles local vendor folder usage for remote modules and a node_modules folder for npm packages.

Options Jump to heading

Type-check all code, including remote modules and npm packages.

--allow-import, -I<IP_OR_HOSTNAME>optional
Jump to heading

Allow importing from remote hosts. Optionally specify allowed IP addresses and host names, with ports as necessary. Default value: deno.land:443,jsr.io:443,esm.sh:443,raw.esm.sh:443,cdn.jsdelivr.net:443,raw.githubusercontent.com:443,gist.githubusercontent.com:443.

--cert<FILE>
Jump to heading

Load certificate authority from PEM encoded file.

Enable type-checking of JavaScript files (equivalent to compilerOptions.checkJs: true).

Use this argument to specify custom conditions for npm package exports. You can also use DENO_CONDITIONS env var. .

Configure different aspects of deno including TypeScript, linting, and code formatting. Typically the configuration file will be called deno.json or deno.jsonc and automatically detected; in that case this flag is not necessary.

--deny-import<IP_OR_HOSTNAME>optional
Jump to heading

Deny importing from remote hosts. Optionally specify denied IP addresses and host names, with ports as necessary.

Type-check code blocks in JSDoc as well as actual code.

Type-check code blocks in JSDoc and Markdown only.

--minimum-dependency-age<minimum-dependency-age>
Jump to heading

(Unstable) The age in minutes, ISO-8601 duration or RFC3339 absolute timestamp (e.g. '120' for two hours, 'P2D' for two days, '2025-09-16' for cutoff date, '2025-09-16T12:00:00+00:00' for cutoff time, '0' to disable).

--no-code-cache
Jump to heading

Disable V8 code cache feature.

--no-config
Jump to heading

Disable automatic loading of the configuration file.

--v8-flags<V8_FLAGS>optional
Jump to heading

To see a list of all available flags use --v8-flags=--help Flags can also be set via the DENO_V8_FLAGS environment variable. Any flags set with this flag are appended after the DENO_V8_FLAGS environment variable.

Last updated on

你找到了你需要的东西吗?

编辑此页面
隐私政策