Combining multiple imports into one typescript

Viewed 1173

I want to imports as follows from the firebase-admin, but TypeScript is not allowing me to do so:

import * as firebase from 'firebase-admin';
import * as admin from 'firebase-admin';

I'm ending up with the following error:

ERROR: 17:1   no-duplicate-imports  Multiple imports from 'firebase-admin' can be combined into one.

I tried using following but none works:

import * as firebase, admin from 'firebase-admin';
import * as firebase, * as admin from 'firebase-admin';

Is there any way to import these two together in TypeScript?

3 Answers

Import only once and put the other in a constant

import * as firebase from 'firebase-admin';
const admin = firebase

You cannot add multiple imports statement from the same module. What you can do is Import once and use that constant to access different modules from the same.

Please refer to the following as multiple imports are not allowed by es

https://eslint.org/docs/rules/no-duplicate-imports

let's remember a basic principle separation of concerns. let's start by refactorying the file structures

- src
-- firebase
---- admin.js
---- regular.js
---- visitor.js
---- index.js

then on the index.js, you could have some like:

import * as admin from "./admin";
import * as regular from "./regular";
import * as visitor from "./visitor";

export const firebase = {
  admin, regular, visitor
};
Related