How to check types for the entire project via CLI? #12113
Replies: 6 comments 14 replies
-
Deno currently does not have a concept of a "project". If you Also, |
Beta Was this translation helpful? Give feedback.
-
Here is what I came up with: #!/usr/bin/env -S deno run --allow-read --allow-write --allow-run
// @ts-check
// Type checks every JavaScript module in the project.
import { expandGlob } from "std/fs/mod.ts";
const typeCheckIndexModuleName = "type-check-index.mjs";
console.log("Creating a temporary index module to check…");
let rawModule = "";
for await (const { path } of expandGlob("**\/*.mjs")) {
rawModule += `import "${path}";\n`;
}
await Deno.writeTextFile(typeCheckIndexModuleName, rawModule);
console.log("Checking the temporary index module…");
const process = Deno.run({
cmd: ["deno", "check", typeCheckIndexModuleName],
stdout: "piped",
stderr: "piped",
});
const { code } = await process.status();
const rawOutput = await process.output();
const rawError = await process.stderrOutput();
if (code === 0) await Deno.stdout.write(rawOutput);
else await Deno.stderr.write(rawError);
console.log("Deleting the temporary index module…");
await Deno.remove(typeCheckIndexModuleName);
Deno.exit(code); It can be run in the project directory by running this: ./scripts/type-check.mjs |
Beta Was this translation helpful? Give feedback.
-
I think the behaviour of least surprise would be for I find myself running the following quite often:
And having to explain this to other devs, and hope their shell supports globs. It's frustrating that can't be added as a task, as tasks don't yet support globs. It would be far more intuitive to just be able to do:
Which could also easily be added as a task too. |
Beta Was this translation helpful? Give feedback.
-
Is this something that a PR would be welcome for? I also think {
"tasks": {
"pre-commit": "deno lint && deno check --all *.ts && deno test"
"setup-pre-commit": "echo '#!/bin/sh\ndeno task pre-commit' > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit"
}
} |
Beta Was this translation helpful? Give feedback.
-
It would be useful if |
Beta Was this translation helpful? Give feedback.
-
On GitHub actions, I needed to use I think deno should support |
Beta Was this translation helpful? Give feedback.
-
There is an issue about introducing a
deno check
CLI command, which presumably would allow TypeScript types to be checked for the entire project via CLI (for CI), but that could be weeks/months away from a resolution so how do we do it today?Beta Was this translation helpful? Give feedback.
All reactions