I'm being stuck trying to understand module things in typescript lang with AMD (i'm using RequireJS); the jQuery.d.ts typings I've downloaded from here contains the following lines at the end of the file:
declare module "jquery" {
export = $;
}
declare var jQuery: JQueryStatic;
declare var $: JQueryStatic;
I'm trying to understand what's the most correct way to import the jquery module.
So far i'm using
import $ = require('jquery');
this seems to correctly load the jquery definition type (i've intellisense on $ object) and at the same time it generates the js:
define(["require", "jquery"], function(require, $) { ... }
so that requireJs can correctly download the library when need it.
1) Am I doing it right?
The official docs says that
When importing a module using export =, TypeScript-specific import let = require("module") must be used to import the module.
But the official lang spec says:
Import require declarations exist for backward compatibility with earlier versions of TypeScript. ImportRequireDeclaration: import BindingIdentifier = require ( StringLiteral );
2) So is the syntax "import identifier = require (string) deprecated? Should I use instead
import * as $ from 'jquery';
3) The official lang spec also says:
Export assignments exist for backward compatibility with earlier versions of TypeScript. An export assignment designates a module member as the entity to be exported in place of the module itself. ExportAssignment: export = IdentifierReference ;
4) So is the "export = $;" syntax in jquery.d.ts deprecated?
5) If i'd like to write my own "module", how can I import it using a non-relative way? I wouldn't like to use:
import * as mymodule from '../myfolder/mymodule';
Instead i'd like to use:
import * as mymodule from 'mymoduleName';
Is there a way to do it? How should I declare my module? "declare module" syntax? "export =" syntax ? Something else?
6) Am I the only one who things this stuff (and the official docs) is really confusing?
Thank you, guys.