javascript - Typescript import/as vs import/require? -
this question has answer here:
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 new
able - 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
Post a Comment