When to use import style for CommonJs (node) modules in Typescript?

It seems that there are different forms of import in Typescript for CommonJS (node) style modules:

If I have a clean javascript module (without defining the environment), this looks fine:

var pureJavascript = require("pure-javascript");

But use is importnot performed on pure javascript modules:

import pureJavascript = require("pure-javascript");

If I do not have an environment definition for the javascript module. Then i can use

import * as jsWithAmbient from "js-with-ambient";

If the module exports fooand bar, I can also use

import {foo} from "./my-module";
import {foo, bar} from "./my-module";
import {foo as x, bar as y} from "./my-module";

Sometimes this seems to be a way to import:

import abc from "./my-module";

which seems the same as

import {default as abc} form "./my-module";

When to use which of the import styles?

+4
source share

Source: https://habr.com/ru/post/1629046/


All Articles