2

I am using "ag-grid": "4.0.5" in a project with Angular 1.5.2 and Typescript with Visual Studio 2015.

The type definitions available for tsd (with the command tsd install ag-grid --resolve --save installs the following: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/ag-grid but this seems to be a very old version 2.1.2 and basically nothing is useful for my project.

I've seen this project has been developed using typescript. Is there any way I can use the project's internal typescript definitions in my project? I have tried adding /// <reference path="../../bower_components/ag-grid/main.d.ts" /> on the top of my TS file but as there are no modules/namespaces on that type definition I cannot reference types like before (e.g: ag.grid.GridOptions) nor I can reference types as if they were available globally (e.g: let test: GridOptionsWrapper) My typescript file won't compile.

I am using Visual Studio 2015 as IDE and if there is another way to make Visual studio aware of the internal type definitions at /// <reference path="../../bower_components/ag-grid/main.d.ts" /> I don't know how to do so..

Anyone with similar situation?

PS: See https://www.ag-grid.com/forum/showthread.php?tid=3581&pid=8414 for further details

UPDATED: I tried the import recommendation as per Niall's answer but as soon as I include the import statement, my internal angular modules cannot be found. Example: I can add: import bb = require("../../bower_components/ag-grid/main.d"); then the intellisense for bb. works perfectly finding all the types within the main.d.ts, but then a line such as let a:app.services.IMyService stops compiling saying that Module 'app' has no exported member services. That was working before adding that require line.

If I simply add /// <reference path="../../bower_components/ag-grid/main.d.ts" /> then it fails to compile with an error Cannot compile modules unless the '--module' flag is provided. I cannot find answers to why I am getting this error.

diegosasw
  • 13,734
  • 16
  • 95
  • 159

1 Answers1

0

The typescript definitions are provided with the project. see main.d.ts file (in root of project).

If you are using TypeScript yourself, just reference the files using 'import', then your IDE should pick up the typings automatically.

Or you can reference them directly using typescript <reference> tag, either point to main.d.ts file, or reference the files in dist/lib

Note that the typescript files are included in the project src), so you could reference the typescript files directly, bypassing the need for typings.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Niall Crosby
  • 2,383
  • 15
  • 16
  • could you show me an example of the import and the typescript tag? I don't seem to get it working. I'd expect to be able to reference, like you said, the main.d.ts with the `/// ` but it doesn't compile nor it has intellisense working. – diegosasw Mar 28 '16 at 20:05
  • that would be only valid if I am using the commonJs version instead the bundled version, isn't it? I am using the bundled version so I don't import modules. – diegosasw Jul 19 '16 at 23:06
  • 1
    an advise for newcomers: adopt as soon as possible some javascript module pattern: AMD, CommonJs, etc. instead using the bundled version and referencing it in the `index.html` so that these problems can be avoided – diegosasw Jun 15 '17 at 21:24