Yuze Ma
Yuze Ma

Reputation: 355

How can I convert from default export to normal export in typescript

I read this post, and this one, and figured it is probably not a good idea to use default export. However, when I was trying to change my code, I ran to an issue: there some variables/objects/functions are not clearly defined to be export. For example:

import * as express from 'express';
import { Controller } from './controller';

const controller = new Controller();

express.Router()
    .post('/', controller.create)
    .get('/', controller.all)
    .get('/:id', controller.byId);

export default express.Router();

I wonder how can I declare the export so it won't use the default export. I tried

export = express.Router

But I feel that is not a good practice as well. Any ideas?

Upvotes: 1

Views: 141

Answers (1)

lukas-reineke
lukas-reineke

Reputation: 3322

Default exports are not bad if you use them right. In this example it is totally fine.

But if you want to give it a name, just assign it to a variable.

export const router = express.Router();

Upvotes: 2

Related Questions