deno icon indicating copy to clipboard operation
deno copied to clipboard

Remove type checking for unanalysable dynamic imports

Open nayeemrmn opened this issue 2 years ago • 1 comments

For dynamic imports with non-static-string specifiers like await import("./" + "foo.ts"), we do a separate type check at runtime with the imported module as the root. Users write these when importing a directory of modules or something. I propose to no longer type check these, for the following reasons:

  1. As of 1.23.0, the primary workflow is checking ahead of time with deno check or your editor, and not checking during deno run. That already aligns with the proposed behaviour. The only way then to type check these truly dynamic imports is deno run --check, which is an awkward discrepancy. So I think we shouldn't do it then either.
  2. When do you really ever want to see type checking errors part way through execution of your program? Users should instead have a dynamic_imports.ts (maybe auto-generated by scanning a directory) which tracks such imports and is checked statically in CI: deno check main.ts dynamic_imports.ts.
  3. The way we check these dynamically discovered graph segments is not even correct. For example if the static graph includes global augmentations, the type check for the dynamic module is not aware of those unless it for some reason imports back into the augmenting module. This sort of incremental addition to a type-checked graph is not a thing in tsc-world. We don't have the prior art or tools to do such a thing correctly.

Note that points 1 and 2 apply to web workers as well, but let's leave those out of scope for now. Eventually I think we should do the same thing for them and introduce deno check --worker.

nayeemrmn avatar Jun 15 '22 18:06 nayeemrmn

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 08 '22 21:09 stale[bot]