Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
ES6 - How to import and alias a named export's member?

Say I have a package that exports a User type:

export const User: {
  name: string;
};

And I want to use the name property aliased as username in my code. In normal JavaScript I'm able to do something like this:

const { User: { name: username } } = require('user.js');

/* do something with `username` ... */

I want to convert the file I'm working with into TypeScript and so I'll use ES6 module imports. How can I achieve the same as above using import instead of require?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can't destructure objects in static import statements, but you can rename them using the as keyword:

import {User as USER} from './user.js';

If you are okay with using a dynamic import, you can destructure:

const {User: {name: username}} = await import('./user.js');

There are pros and cons to both static and dynamic importing methods which you can read about in the links I shared.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!