打字稿的不同导入和导出形式
different import and export form of typescript
我是打字新手。任何人都可以向我解释这些出口之间的区别:
export default class Foo {}
/* or */
class Foo {}
export = Foo;
/* or */
export class Foo { }
以及这几种导入形式的区别:
import x = require('y');
import x from 'y';
import { x } from 'y'
import * as x from 'y';
什么时候使用它们?
export default class Foo {}
// and
import x from 'y';
Each module can optionally export a default export. Default exports
are marked with the keyword default; and there can only be one default
export per module. default exports are imported using a different
import form.
export = Foo;
// and
import x = require('y');
Both CommonJS and AMD generally have the concept of an exports object
which contains all exports from a module.
They also support replacing the exports object with a custom single
object. Default exports are meant to act as a replacement for this
behavior; however, the two are incompatible. TypeScript supports
export = to model the traditional CommonJS and AMD workflow.
The export = syntax specifies a single object that is exported from
the module. This can be a class, interface, namespace, function, or
enum.
When importing a module using export =, TypeScript-specific import let
= require("module") must be used to import the module.
您包含的其他表格:
export class Foo { }
// and
import { x } from 'y'
import * as x from 'y';
是export and import的正常形式。
它基于 es6 import/export 语法,您也可以在 MDN 中找到更多信息:import / export.
我是打字新手。任何人都可以向我解释这些出口之间的区别:
export default class Foo {}
/* or */
class Foo {}
export = Foo;
/* or */
export class Foo { }
以及这几种导入形式的区别:
import x = require('y');
import x from 'y';
import { x } from 'y'
import * as x from 'y';
什么时候使用它们?
export default class Foo {}
// and
import x from 'y';
Each module can optionally export a default export. Default exports are marked with the keyword default; and there can only be one default export per module. default exports are imported using a different import form.
export = Foo;
// and
import x = require('y');
Both CommonJS and AMD generally have the concept of an exports object which contains all exports from a module.
They also support replacing the exports object with a custom single object. Default exports are meant to act as a replacement for this behavior; however, the two are incompatible. TypeScript supports export = to model the traditional CommonJS and AMD workflow.
The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.
When importing a module using export =, TypeScript-specific import let = require("module") must be used to import the module.
您包含的其他表格:
export class Foo { }
// and
import { x } from 'y'
import * as x from 'y';
是export and import的正常形式。
它基于 es6 import/export 语法,您也可以在 MDN 中找到更多信息:import / export.