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");
We can divide the module into two categories: Internal Module. External Module.
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.
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.
There are two possible module resolution strategies: Node and Classic.
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.
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