Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove type checking for unanalysable dynamic imports #14877

Closed
nayeemrmn opened this issue Jun 15, 2022 · 2 comments · Fixed by #22854
Closed

Remove type checking for unanalysable dynamic imports #14877

nayeemrmn opened this issue Jun 15, 2022 · 2 comments · Fixed by #22854
Labels
tsc related to the TypeScript tsc compiler

Comments

@nayeemrmn
Copy link
Collaborator

nayeemrmn commented Jun 15, 2022

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.

@stale
Copy link

stale bot commented Sep 8, 2022

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 stale bot added the stale label Sep 8, 2022
@stale stale bot closed this as completed Sep 16, 2022
@kitsonk kitsonk added suggestion suggestions for new features (yet to be agreed) tsc related to the TypeScript tsc compiler and removed stale labels Sep 16, 2022
@kitsonk kitsonk reopened this Sep 16, 2022
@dsherret
Copy link
Member

We should do this. It will also cause problems for no-slow-types in JSR.

@dsherret dsherret added enhancement and removed suggestion suggestions for new features (yet to be agreed) labels Feb 25, 2024
dsherret added a commit that referenced this issue Mar 13, 2024
In addition to the reasons for this outlined by @nayeemrmn in #14877
(which I think are reasons alone to not do this), this simplifies things
a lot because then we don't need to implement the following:

1. Need to handle a JSR module dynamically importing a module within it.
2. Need to handle importing an export of a JSR dep then another export
dynamically loaded later.

Additionally, people should be running `deno check dynamic_import.ts`
instead of relying on this behaviour.

Landing this as a fix because it's blocking people in some scenarios and
the current behaviour is broken (I didn't even have to change any tests
to remove this, which is bad).

Closes #22852
Closes #14877
Closes #22580
nathanwhit pushed a commit that referenced this issue Mar 14, 2024
In addition to the reasons for this outlined by @nayeemrmn in #14877
(which I think are reasons alone to not do this), this simplifies things
a lot because then we don't need to implement the following:

1. Need to handle a JSR module dynamically importing a module within it.
2. Need to handle importing an export of a JSR dep then another export
dynamically loaded later.

Additionally, people should be running `deno check dynamic_import.ts`
instead of relying on this behaviour.

Landing this as a fix because it's blocking people in some scenarios and
the current behaviour is broken (I didn't even have to change any tests
to remove this, which is bad).

Closes #22852
Closes #14877
Closes #22580
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tsc related to the TypeScript tsc compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants