Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

typescriptのimport/export

一つだけ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をした場合に互換性を維持する場合につかう?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
3
Help us understand the problem. What are the problem?