-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
File '@types/office-js/index.d.ts' is not a module #11420
Comments
I have the same issue with node File '../node_modules/@types/node/index.d.ts' is not a module. |
@rameshsubramanian there is no module called "node". you can not |
@jozefizso the issue is the d.t.s file for export = Office; // make it a module
export as namespace Office; // keep a global namespace called Office |
This will display error TypeScript 2.0 should work with definitions from |
it does work with @types. the contents of the declaration file is not something we control. these come form the community on https://github.com/DefinitelyTyped/DefinitelyTyped. If you see issues with this declaration file, you can file an issue on https://github.com/DefinitelyTyped/DefinitelyTyped or send a PR with a fix. once a fix has been made on https://github.com/DefinitelyTyped/DefinitelyTyped, a new @types package will be published automatically. Looking more into it, i do not see any where in the docs that office-js can be used as a module. |
@Zlatkovsky is the original contributor for this declaration file, he might have some insight. |
It's a declaration file of |
The declaration file does not say that there is a module called please see http://www.typescriptlang.org/docs/handbook/modules.html for more details about modules. |
Regarding Office.js: "Office" is a module, in the sense that you should be able to call "Office.context.document.getSelectedDataAsync", or "Excel.run(function() { ... })". I have not used it with "import ..." syntax before, but let me see if someone on my team has. I'll get back to this thread when I find out more info. |
@jozefizso When you use an import syntax, Typescript is looking for a 'module' i.e. a commonjs, amd, systemjs or umd module, that is available in the node_modules folder as an npm package. Office.js currently uses the module (aka. namespaces) system to add its contents as a Global window variable and hence the module loaders won't work with that, as the Office module isn't being exported. That being said, you could be clever and add a configuration in your require.js or system.js saying that 'office-js' is a npm package located @ weburl but due to the nature of how Office.js works, you wont be able to achieve the same. Hence you can't exactly 'import' office-js. For now, the best approach is to
The point of the office.d.ts is to allow developers to use OfficeJS with intellisense and make it easy to develop add-ins. That said we understand the fact that developers love to have 'modules' that are importable and we are looking into how to get Office.js there. Let me know if that answers your questions else i'd be glad to clarify further. |
I understand the Office.js library will create global Can't TypeScript help me with a useful message that I should use the reference syntax (in fact, it is not needed at all) because I cannot import TypeScript definition file that does not contain a module? |
@jozefizso Did you figure a syntax that allowed you to use the office-js type def? Trying to use it within an Angular (ng4) application and have been baffled all day trying all sorts of options... but at a loss. |
@andrewconnell: I had a similar problem getting the "Flickity" library to run in an Angular 2 project. I could get it to work as follows:
|
My apologies to anyone getting spammed with an email from this comment, but since it took me awhile to figure out how to do something like this, I thought I would share. For me, running and then adding a line like seems to have worked :) More information here on the |
TypeScript Version: 2.0.3
Code
Install
office-js
types definition:Try to use the
Office
object inapp.ts
:TypeScript configuration in
tsconfig.json
:Expected behavior:
TypeScript 2.0 should use the types definitions that are available from
npm @types
.Actual behavior:
TypeScript reports error: File 'node_modules/@types/office-js/index.d.ts' is not a module.
TypeScript does not recognize the
Office
as valid object and does not provide intellisense.The text was updated successfully, but these errors were encountered: