Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between declaring a module in TypeScript with quotes vs without?

Tags:

typescript

I am a beginning at writing TypeScript definition files and would like to know the difference between the following two constructs:

declare module activedirectory

and

declare module "activedirectory"

For some reason the former allows me to utilize any classes within one of my Angular services without any sort of import declaration (ex. import activedirectory = require('activedirectory'). Whenever I declare the latter in my code, it destroys references to my internal modules, for example:

module myModule.Services {
    'use strict';

    export class MyService implements myModule.Interfaces.IMyService {
    .....

Can no longer locate the "myModule.Interfaces" namespace.

like image 863
cjones26 Avatar asked Sep 11 '15 17:09

cjones26


1 Answers

The TypeScript team recognized the confusion, and that's why modules without quotes are now called namespaces.

Going forward, internal modules will be called ‘namespace’. We chose to use this term because of the closeness between how this form works and namespaces in other languages [...] http://blogs.msdn.com/b/typescript/archive/2015/07/20/announcing-typescript-1-5.aspx

The quoted modules are ES6 modules, and need to be be imported using an import statement like import 'activedirectory';

like image 119
thoughtrepo Avatar answered Sep 24 '22 14:09

thoughtrepo