Typescript import statement

I am trying to understand what the other es syntax does import, and when I need to use them.

I am using typescript 1.6 (latest version at the moment).

I have seen some import examples. One is as follows:

import {Aurelia} from "aurelia-framework";

Which gives me access Aureliafrom the Aurelia Framework. I more or less get this one, but I'm not sure where exactly the part is in the quotes.

Here is another one that resharper inserted into my code:

import myJsServiceActions = require("../../service_actions/myJsFile");

It also gives me access to materials in myJsFile. But the syntax is completely different. And it looks like a path reference in quotation marks.

Also this one does not use curly braces {} like the first one. When I try to add something like {ServiceActions} (the module in this file), it gives an error message requiresaying that a string literal is expected.

What's new in this second use (from the first)?

I also saw these customs on the Internet, but I assume they are just the older syntax (if they are still in use, indicate how they differ):

/// <reference path="myModules.d.ts" />
....
import gt = module('greeter'); 

And finally, how does he find the material in quotation marks? I tried this:

import breeze from "breeze";

and I get the error:

Unable to find the breeze module

But in my config.js they are defined right next to eachother:

map: {
    //....
    "aurelia-framework": "github:aurelia/framework@0.18.0",
    "breeze": "npm:breeze-client@1.5.5",
   //.....
  }

It seems to me that if aurelia-framework import works, then the breeze should work too. But I suppose this is my ignorance of how the “imports” work, which causes the problem.

+4
1

.

  • , declare module "aurelia-framework"
  • aurelia-framework (Node ( --module commonjs node).

, resharper :

.d.ts .ts .tsx .

import foo from "foo" vs import foo = require('foo')

ES6 ( ES6), - nodejs ( var foo = require('foo'))

import breeze from "breeze";

, import * as breeze from "breeze"

+2

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


All Articles