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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With