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

Unique compiler warning for libraries without type information #11060

Closed
DataTables opened this issue Sep 22, 2016 · 4 comments
Closed

Unique compiler warning for libraries without type information #11060

DataTables opened this issue Sep 22, 2016 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@DataTables
Copy link

TypeScript Version: 2.0.2 && 2.1.0-dev.20160922

Code

Import a npm sourced module which you haven't installed an @type/ definition for.

Expected behavior:

Compiler warning that it couldn't find typing information for the module.

Actual behavior:

Compiler warning saying that it can't find the module:

error TS2307: Cannot find module 'express-session'.

2.0.0 didn't have this behaviour, then which I upgraded to 2.0.2 I started getting errors about modules which I knew I had npm installed not existing. It took a while to realise that the issue was tsc didn't have the @type definitions for those modules.

It would be really useful to have the compiler's warning change for such a case - for example:

Cannot find type information for module 'express-session'

This isn't a bug report as such, as its all working, but rather a request that the information emitted by the compiler be clearer.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 22, 2016

2.0.0 didn't have this behaviour,

This has been the same message since 0.9.*. Looks like there was a file that 1.8 picked up that is not picked up now. where was your module declared without installing @types? if you run tsc --listFiles do you see that file? is the containing file in an exclude list?

It would be really useful to have the compiler's warning change for such a case - for example:
Cannot find type information for module 'express-session'

The thing is the compiler is only looking for the type information all the time. it looks for a .ts file if one is available, if not then a .d.ts if not looks for a global declaration of the shape declare module "mod" { ... }. so really this is what the error is all about.

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Sep 22, 2016
@DataTables
Copy link
Author

where was your module declared without installing @types?

I had npm installed it, but without the type information (either an @type module, or a .d.ts file). I was simply doing an import * as from 'module-name' which resulted in no errors with 2.0.0.

The thing is the compiler is only looking for the type information all the time.

Its probably my understanding of how TypeScript works (still finding my feet), but if I have a typo in my import module name I get the same error (this is with 2.0.2):

error TS2307: Cannot find module 'express-hand'.

That seems like the right error for that kind of issue to me - it can't find that module in the node_modules directory (and wherever else it scans).

What confused me is that the compiler is emitting the same error for the case where the module isn't present as when there is no typing information for that module. Perhaps internally they are the same thing, but externally its two different npm modules to install and the compiler doesn't offer any indication as to which one is missing.

Kudos on the 2.0 release btw - I'm loving TypeScript :-)

@mhegazy
Copy link
Contributor

mhegazy commented Sep 22, 2016

Its probably my understanding of how TypeScript works (still finding my feet), but if I have a typo in my import module name I get the same error (this is with 2.0.2):

from the compiler perspective it does not make a difference. it only looks for a module "foo". It needs to know the "shape" of "foo" be it in a file or not. it does not know if you missspelled it and meant "foobar" or just did not write the definition for it yet.

Module resoluton documentation might be helpful here: http://www.typescriptlang.org/docs/handbook/module-resolution.html

What confused me is that the compiler is emitting the same error for the case where the module isn't

I suppose we can do one pass after we find the error to see if a .js file exists somewhere, and issue a follow up message if only the declaration file is missing.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 23, 2016

#11106 seems to have a proposal for solving this issue that we can implement. closing in favor of #11106

@mhegazy mhegazy closed this as completed Sep 23, 2016
@mhegazy mhegazy added Duplicate An existing issue was already created and removed Needs More Info The issue still hasn't been fully clarified labels Sep 23, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

1 participant