---
title: "Refactor your code using renaming Imports"
date: "2021-04-06"
slug: "refactor-your-code-using-renaming-imports"
author: "Dany Paredes"
canonical: "https://danywalls.com/refactor-your-code-using-renaming-imports"
description: "I'm refactoring an Angular code, and I need to have the same filenames while finishing the refactor. My solution was to rename my imports. It is a great way to use a different name or alias for my classes and modules. For example, you can import a si..."
---

I'm refactoring an Angular code, and I need to have the same filenames while finishing the refactor.

My solution was to rename my imports. It is a great way to use a different name or alias for my classes and modules.

For example, you can import a single class using the keyword
```js
import {Player as NbaPlayer} from './nba'
```
Or import the full module using *
```js
import * as NbaLeage from './nba'
```
Then you can use your aliases in your application without a problem.

Example:
```js
import { Player, Team }       from './nba';
import { Player as NbaPlayer} from './nba';
import * as NbaLeage          from './nba';

let lebron = new Player('Lebron', 'SF');
let carmelo = new NbaLeage.Player('Carmelo', 'SF');
let curry = new NbaPlayer('curry', 'PG');

let players : Array<NbaPlayer> = [ carmelo, curry, lebron];

players.forEach(player => console.log(player.name));
```
Have a nice day!

Picture
https://unsplash.com/photos/yhNVwsKTSaI

