Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript 'using' [duplicate]

Tags:

typescript

In C# one can use a using clause at the top of your file, which enables the use of types within that namespace without explicitly having to specify the full namespace to reference those types. Does TypeScript provide an alternative for that?

like image 692
Paul0515 Avatar asked Feb 06 '13 09:02

Paul0515


People also ask

How can I check if the array of objects have duplicate property values?

Using the indexOf() method In this method, what we do is that we compare the index of all the items of an array with the index of the first time that number occurs. If they don't match, that implies that the element is a duplicate. All such elements are returned in a separate array using the filter() method.


1 Answers

In TypeScript the closest you can come to being able to directly use external modules is aliasing. As shown in the TypeScript Handbook, it is used like this:

module Shapes {
    export module Polygons {
        export class Triangle { }
        export class Square { }
    }
}

import polygons = Shapes.Polygons;
var sq = new polygons.Square(); // Same as 'new Shapes.Polygons.Square()'

This doesn't put the interfaces on the root scope of the module because this could introduce naming conflicts if the Polygons module was updated and makes it clear that you are referencing something external.

like image 70
Chic Avatar answered Oct 06 '22 19:10

Chic