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

(bug) short-hand module declaration not working in combination with 'noImplicitAny' #10191

Closed
choeller opened this issue Aug 7, 2016 · 5 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@choeller
Copy link

choeller commented Aug 7, 2016

TypeScript Version: 2.1.0-dev.2016080

Code
Trying to declare a module with the new short-hand syntax like this:

  declare module 'lodash';

leads to the following TypeScript-Compiler error

error TS7005: Variable ''lodash'' implicitly has an 'any' type.

I also can't find a way to make this "explicit any".

Expected behavior:

new shorthand syntax for module-declaration should also work with 'noImplicitAny' activated

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Aug 7, 2016
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.0.1 milestone Aug 7, 2016
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Aug 7, 2016

Actually from the source code

// Ambient shorthand module is an implicit any

At the very least, the error message you got is bad.

@mhegazy @andy-ms @RyanCavanaugh do we really want to consider this an implicit any? The entire point of noImplicitAny was to warn when the type system couldn't figure out the type of something. Here, you didn't expect the type system to figure anything out. You just wanted it to be quiet about something else and it yelled at you about your fix. The solution isn't any better than the original problem.

@RyanCavanaugh
Copy link
Member

I don't see why we should make you write a type annotation either. It's just ceremony and the thing you have to write is very awkward.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 16, 2016

but the module import is typed implicitly as any. how is this different from declare var $. we force you to write :any or it is an error.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 16, 2016

the question here is why use declare module 'lodash'; instead of including the declaration file for lodash?

@choeller
Copy link
Author

choeller commented Aug 17, 2016

mhegazy I would be happy, If I could say

declare module 'myuntypedmodule': any;

but AFAIK there is just no way to do this. lodash was just an example. We are integrating a lot of legacy libs in our project, so this is where this short-hand syntax could be useful.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Aug 17, 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
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants