Skip to content

Import path not checked when not importing any symbols #20534

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

Closed
jamietre opened this issue Dec 7, 2017 · 3 comments
Closed

Import path not checked when not importing any symbols #20534

jamietre opened this issue Dec 7, 2017 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@jamietre
Copy link

jamietre commented Dec 7, 2017

Typescript version: 2.6.1

Code

import foo from 'some/valid/module'
> no errors!

import foo from 'something/nonexistent'
> TS2307: Cannot find module 'something/nonexistent'

import 'something/nonexistent'
> no errors!

Expected behavior:

Import statements that don't import any symbols should be checked the same as any other.

Actual behavior:

If you don't import a symbol, the import target is not validated to resolve correctly.

tsconfig.json:

{
  "compilerOptions": {
    "jsx": "react",
    "moduleResolution": "node",
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "removeComments": true,
    "strictNullChecks": true,
    "target": "ES6"
  },
}
@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 11, 2017
@RyanCavanaugh
Copy link
Member

I can't find the issue because "import" + "error" = all the issues, but this is the intended behavior as per many requests from users to support scenarios such as importing CSS modules for their side effects without having to write empty declaration files for them

@jamietre
Copy link
Author

jamietre commented Dec 13, 2017

So in order to support using import statements to resolve non-Typescript/non-Javascript files, any import statement that doesn't resolve an export from a module is essentially not checked at all?

This seems very counterintuitive. It's perfectly valid ES6 syntax to import JavaScript modules without importing any symbols in order to ensure (say) global dependencies or other bootstrapping is resolved; I would think allowing importing things that aren't actually code should be the exception rather than the rule and have some special handling if needed.

This should at the very least be a user-configurable compilation option. And even if we decide we aren't going to typecheck the static dependency (e.g. since it's CSS), we should still at least ensure it exists! But ideally, we'd ensure ALL import targets exist, and ones that are actually typescript (or javascript if using allowJs) would also by compiled normally as would be any other static code dependency. Right now, as far as I can tell, such imports are completely ignored.

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants