Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the three ways of loading typescript module dependencies?

What is the difference between the following ways of loading typescript module dependencies?

/// <amd-dependency path="someFile"/>

/// <reference path="someFile.ts" />

import someFile = require("someFile");
like image 701
Nefarious Avatar asked Apr 08 '15 19:04

Nefarious


People also ask

How many types of modules are there in TypeScript?

We can divide the module into two categories: Internal Module. External Module.

What is module loader in TypeScript?

At runtime the module loader is responsible for locating and executing all dependencies of a module before executing it. Well-known module loaders used in JavaScript are Node. js's loader for CommonJS modules and the RequireJS loader for AMD modules in Web applications.

What is the module and how it can be imported and exported in TypeScript with example?

A module can be created using the keyword export and a module can be used in another module using the keyword import . In TypeScript, files containing a top-level export or import are considered modules. For example, we can make the above files as modules as below. console.

What are the two possible module resolution strategies?

There are two possible module resolution strategies: Node and Classic.


1 Answers

Covered here : https://typescript.codeplex.com/wikipage?title=Modules%20in%20TypeScript

Disclaimer : My strong opinions follow : https://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1

import someFile = require("someFile");

This should be your main form of import. Use this for JS libraries import $ = require("jquery"); as well as its relative file variant for your own files import someFile = require("./someFile");

/// reference path="someFile.ts" /

use this only to import type information from .d.ts files and your very own globals.d.ts or vendors.d.ts or tsd.d.ts

amd-dependency path="someFile"

You don't need this unless you want to require stuff in CSS / images into your TS.

like image 58
basarat Avatar answered Oct 12 '22 08:10

basarat