javascript - Typescript import/as vs import/require? -


i using typescript express/node.js.

for consuming modules, typescript handbook shows following syntax:

import express = require('express');

but typescript.d.ts file shows:

import * express "express";

i searched msdn blog not find anything.

which 1 more correct of 2016? differences between two, if any?

where best source find information on latest syntax use can find information in future?

these equivalent, import * has restrictions import ... = require doesn't.

import * as creates identifier module object, emphasis on object. according es6 spec, object never callable or newable - has properties. if you're trying import function or class, should use

import express = require('express'); 

or (depending on module loader)

import express 'express'; 

attempting use import * express , invoking express() illegal according es6 spec. in runtime+transpilation environments might happen work anyway, might break @ point in future without warning, make sad.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -