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

255
Views
Can we Use Generic Variable to Make an import with TypeScript

I searched a lot,for a solution to create a basic generic component. For this i need to pass throught props an Array of Objects to a functionnal Component.

On this functionnal component i want to use dynamic values coming from Props like import MyDynamicName from "DynamicPath"

Example

import myComponentName from myPathVar

I want to use variables on an import line , this variables coming from _props . And i don't know how to solve this problem and if its possible

i tried this but didn't worked

const path = '../../examples/tagsProjectsa.json';
const abc = import(`${path}`).then(data => {
  console.log(data);
});

but module can't be found

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

0

Static import statements cannot be used to resolve a dynamic specifier. From the linked documentation:

Only single quoted and double quoted Strings are allowed.

However, you can resolve a dynamic specifier (e.g. a string held in a variable) using dynamic import. This even works using object URLs as seen in the code snippet below:

You appear to be attempting to import JSON data. Note that importing JSON data is not yet part of the spec, and that doing so requires using an import assertion which is currently only a stage 3 proposal.

<script type="module">

const initialData = {message: 'hello world'};

const json = JSON.stringify(initialData);
const blob = new Blob([json], {type: 'application/json'});
const oUrl = URL.createObjectURL(blob);

const {default: importedData} = await import(oUrl, {assert: {type: 'json'}});

const result = importedData.message === initialData.message ? 'Success' : 'Fail';
console.log(result, {initialData, importedData});

// Cleanup object URL data after use
URL.revokeObjectURL(oUrl);

</script>

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!