Importing TypeScript modules

前端 未结 2 1546
青春惊慌失措
青春惊慌失措 2020-12-05 03:02

I am just trying to get my head around TypeScript,

Say I have a module animals.ts like this:

export module Animals {

    export interfa         


        
2条回答
  •  半阙折子戏
    2020-12-05 03:40

    You can use 2 types of syntaxes export/import:

    1. (AMD style) Require syntax which supported in ES5:

      var animals = require("animals");

    2. Use import style which started suppurts from ES6:

      import { Elephant, Horse } from "animals";

    TypeScript supports export = to model the traditional CommonJS and AMD workflow. So both variants will works and I suggest to use 2nd because it more powerful mechanism.

    More details about it can be found on official the TypeScript Modules web page.

提交回复
热议问题