7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

typescriptのimport/export

Posted at

一つだけexport

myclass.ts
export default class MyClass{}
myclass.js
exports.default = class MyClass{}
main.ts
import MyClass from './myclass'
const mc = new MyClass()

複数export

myclass.ts
export class MyClass1 {}
export class MyClass2 {}
myclass.js
exports.MyClass1 = class MyClass1{}
exports.MyClass2 = class MyClass2{}
main.ts
import {MyClass1, MyClass2} from './myclass'
const mc1 = new MyClass1()
const mc2 = new MyClass2()

import * as MyClass from './myclass'
const mc1x = new MyClass.MyClass1()
const mc2x = new MyClass.MyClass2()

node.jsでmodule.exportsをする必要がある場合

myclass.ts
export = class MyClass{}
myclass.js
moudule.exports = class MyClass{}
main.ts
import MyClass = require('./myclass')
const mc = new MyClass()
  • npm等でmodule.exportsをした場合に互換性を維持する場合につかう?
7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?