denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.42k stars 5.18k forks source link

Disabling type checking for vendored dependencies or directories #14797

Open KyleJune opened 2 years ago

KyleJune commented 2 years ago

I have third party dependencies that work with the default --no-check=remote option. However once I vendor them and updating deno.json to use the vendor/import_map.json, I start getting errors type errors. It appears the only workaround for having my dependencies vendored is to run deno run and deno test with the --no-check flag to disable all checking. I'd like to have checking for my other local files when I run deno test. According to the most recent release blog post, it looks like it's planned to keep local type checking for deno test and to remove it for deno run.

In our deno.json file we can configure deno lint and deno fmt to exclude files and directories. It would be nice if we could do the same with deno's type checking so that we can disable it for the vendor directory generated by deno vendor. That would allow me to use deno vendor without giving up type checking when I run my tests.

Below is an example of one of the type errors I get related to my vendored dependencies. I don't get the type error when not using vendored dependencies.

error: TS2339 [ERROR]: Property 'spawn' does not exist on type 'typeof Deno'. 'Deno.spawn' is an unstable API. Did you forget to run with the '--unstable' flag?
  const { status, stderr } = await Deno.spawn(Deno.execPath(), {
                                        ~~~~~
    at file:///home/kyle/Projects/deno/udibo/vendor/deno.land/std@0.141.0/node/_utils.ts:228:41
KyleJune commented 2 years ago

Here is the temporary workaround I decided on using for now. Using deno check with an empty import map instead of the one in vendor/import_map.json when I want to type check my code. The downside to this is that my test files are unchecked.

deno check --import-map=import_map.json main.ts

Another workaround I thought of was running my tests twice. First with --no-check=remote and the empty import map, then with the vendor import map and type checking disabled. That would allow me to verify types in my local code and that my code runs with my vendored dependencies. The downside to this would be that my ci would fail if my external deps broke, which kind of defeats one of my motivations for using vendored dependencies. I was having code break due to breaking changes on esm.sh when I wasn't using vendoring.

NetOpWibby commented 1 year ago

I'd like a way to disable checks for certain directories. I'm using EdgeDB and it autogenerates code based on your schema. These are the errors I get:

error: TS2590 [ERROR]: Expression produces a union type that is too complex to represent.
> = $.$expr_Function<
    ^
    at file:///~/project/dbschema/edgeql-js/modules/std.ts:1698:5

TS2590 [ERROR]: Expression produces a union type that is too complex to represent.
> = $.$expr_Function<
    ^
    at file:///~/project/dbschema/edgeql-js/modules/std.ts:1753:5

I should be able to ignore dbschema/ within deno.json, the same way I can disable that same directory for linting.