Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Type definitions in global namespace using the 'typings' field of 'package.json' #568

Closed
richardhuaaa opened this issue Jun 1, 2016 · 3 comments
Labels

Comments

@richardhuaaa
Copy link

Description

One of the excellent things about typings is that, if a .d.ts is specified in the 'typings' field of the package.json of a node module, users of editors such as VSCode will automatically get intellisense for that module, even if they are directly writing JavaScript, and without needing to explicitly install any types. An example is here, and it works excellently.

I'd like to do the same for the cordova-plugin-code-push module, however the tricky thing is that we'd like to define objects on the global namespace. However, I am unable to get this to work by following the examples, and this page suggests that, using the package.json, we may not add anything to the global scope.

Adding something to global scope is common practice for Cordova plugins, and hence I imagine a commonly desired thing. Is there any way to achieve this scenario, such that the end user does not need to explicitly install any types?

@blakeembrey
Copy link
Member

@Silhouettes Type definitions using typings in package.json can't be global. If you want to mutate globals and use external modules, you should be using declare global.

@blakeembrey
Copy link
Member

@richardhuaaa
Copy link
Author

Okay, so as far as I understand, we always require the developer to make some kind of explicit reference to the module, such as a require(), and as a module developer we can't create type definitions that are 'automatically' loaded. It would have been nice to be able to do so, but this makes sense, thank you!

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

No branches or pull requests

2 participants