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

index.d.ts in base folder is causing issue with TypeScript #44

Closed
mwilc0x opened this issue Dec 8, 2015 · 8 comments
Closed

index.d.ts in base folder is causing issue with TypeScript #44

mwilc0x opened this issue Dec 8, 2015 · 8 comments
Assignees

Comments

@mwilc0x
Copy link

mwilc0x commented Dec 8, 2015

I installed latest ng-redux module and put it into my project using browserify + tsify (I'm using TypeScript). I've also included the type definitions from the DT repo.

When I include this lib in my project via import 'ng-redux', I get the following error:

Error TS2306: File `node_modules/ng-redux/index.d.ts` is not a module

If I move index.d.ts outside the folder, it will compile properly and include the lib in my project.

Is it possible to move this file into dist folder or another location?

BTW thanks for making this lib, it's very helpful when using redux with ng1!

@wbuchwalter wbuchwalter self-assigned this Dec 8, 2015
@dballance
Copy link
Contributor

Also trying to solve this. I believe it is related to babel 6+ changes, as referenced here.

Unfortunately, I haven't been able to figure out the proper structure yet. I'll issue a pull request if I manage to figure out the syntax that TypeScript wants here.

@mwilc0x
Copy link
Author

mwilc0x commented Dec 10, 2015

Thanks @dballance, that is good information to know.

I see that the type definitions were submitted to DT but were closed a few days ago

I would think the best solution would be to have the type definitions separate from the actual repository if possible. Removing the index.d.ts file from the base directory is what solved the problem for me.

cc @droritos

@wbuchwalter
Copy link
Member

See PR #34 by @sstorie:

I'm trying to confirm this, but I thought at the recent AngularConnect conference there was a typescript talk saying that newer versions of TS will automatically look in npm packages for d.ts files. Including this file in the package would let typescript automatically find the definition file.

If that's causing problems I don't mind moving the typing to DT.

@mwilc0x
Copy link
Author

mwilc0x commented Dec 10, 2015

I get the same error with 1.7. I'm not sure about the auto-discovery of .d.ts files, that would be nice though.

Either way, this should probably be renamed to something other than index.d.ts? I think it's tripping up the compiler which is trying to treat it as the entrance to this module. Similar to this discussion.

@sstorie
Copy link

sstorie commented Dec 10, 2015

The root issue here is the index.d.ts file needs to be updated to act like a external Typescript module, and not like an internal module. I ran into the same problem with some definitions I added to the redux-ui-router library, and required a simple fix to get things working without errors: neilff/redux-ui-router#30.

As for the DT typings, I suggest that once we correct this index.d.ts file to have the right format, you remove the DT typings from your code base. The use of index.d.ts was added to let lib authors include the typings directly with a package, and not force users to get them from somewhere else.

I'm happy to submit a PR that fixes the issue.

@wbuchwalter
Copy link
Member

I just tested declaring the typings as external modules as @sstorie said and it works great, so this is the way to go.
Feel free to submnit a PR, otherwise i'll do it later.
Thanks

@wbuchwalter
Copy link
Member

Released on npm @3.1.2.

@mwilc0x
Copy link
Author

mwilc0x commented Dec 12, 2015

Thank you @wbuchwalter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants