【问题标题】:What is the deno equivalent of node --checknode --check 的 deno 等价物是什么
【发布时间】:2022-02-07 01:45:19
【问题描述】:

在节点中,有一个 --check 选项来检查代码是否对执行有效,如果有效则不实际运行它。 我一直在寻找 deno 中的等价物(deno 帮助、deno 运行帮助、deno lint 帮助)

我能想到的最接近的是deno lint,但它会很高兴地检查以下打字稿代码(在 test.ts 中),deno run 随后拒绝运行(显然)。

什么是典型的 deno “dry run”?

test.ts:

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

【问题讨论】:

  • node --check 仅进行语法检查,因此您的 test.ts 也会通过...
  • @FZs 请注意,问题是关于 typescript,因此是 .ts 扩展名。该代码是有效的 javascript,而不是 typescript
  • 代替更好的答案,我想可以使用deno compile -o /dev/null <script>

标签: deno


【解决方案1】:

检查代码是否可以执行

“试运行”

这些概念不存在。我认为您想要的是使用静态类型检查(不实际运行模块)分析您的 TypeScript 代码。这称为编译,在这种情况下你想要的 Deno 子命令是 cache:

deno cache module.ts

重新缓存入口点模块和所有依赖项:

deno cache --reload module.ts

使用您的示例test.ts:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    • 2015-10-17
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 2014-05-08
    相关资源
    最近更新 更多