Help us understand the problem. What is going on with this article?

typescriptのimport/export

More than 1 year has passed since last update.

一つだけ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をした場合に互換性を維持する場合につかう?
you21979@github
なにごとも初心者です
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした