Note that there are some explanatory texts on larger screens.

plurals
  1. POImport syntax for reference to dgrid from TypeScript
    text
    copied!<p>I am learning TypeScript and Dojo in parallel and this has exposed my limited understanding of AMD. I do not understand how to tie together an import statement to the 3rd party "dgrid/Grid" AMD module, my dgrid.d.ts stub declaration and my consuming class. After 2 days of wasted effort I am looking for any means (hacky or amd best practice) to execute the following:</p> <p><strong>MyModule.ts</strong></p> <pre><code>{ ... var myGrid = new dgrid.Grid( { /*col structure*/}, "divId"); ... } </code></pre> <p>Here is my stub declaration file for dgrid.</p> <p><strong>dgrid.d.ts</strong> (edited to sync with Update 1 below)</p> <pre><code>module "dgrid/Grid" { export class Grid { constructor ( gridStructure: any, elementId: string); } } </code></pre> <p>I tried the following references in my consuming TypeScript class but Visual Studio underlines the "dgrid/Grid" literal in red because I guess the TS compiler is unaware of the classic Dojo dojoConfig, baseUrl and dgrid package declarations in the default.htm file.</p> <pre><code>///&lt;reference path='dgrid.d.ts' /&gt; import Grid = module("dgrid/Grid"); module MyModule { ... } </code></pre> <p><strong>Update 1</strong> Since posting I read through chapter 10 in the official TypeScript manual. Previously I had failed to recognise the significance of modules declared as module MyType{} or module "external/thirdparty" {}. An ambient declaration for an external module should be a literal.</p> <p><strong>Background:</strong></p> <ul> <li>I am using Dojo 1.8.0 referenced from ajax.googleapis.com</li> <li>The dgrid JavaScript is hosted locally in /js/dgrid</li> <li>I am trying to closely follow the SitePen dgrid tutorial page showing classic AMD require() loading of dgrid <a href="http://dojofoundation.org/packages/dgrid/tutorials/hello_dgrid" rel="nofollow">http://dojofoundation.org/packages/dgrid/tutorials/hello_dgrid</a> <a href="http://dojofoundation.org/packages/dgrid/tutorials/hello_dgrid/demo/simple.html" rel="nofollow">http://dojofoundation.org/packages/dgrid/tutorials/hello_dgrid/demo/simple.html</a></li> </ul> <p>Require statement:</p> <pre><code>require(["dgrid/Grid", "dojo/domReady!"], function(Grid){ </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload