M
M
Maxim Zolotoy2021-06-11 09:22:28
typescript
Maxim Zolotoy, 2021-06-11 09:22:28

How to do ES6 import from default directory in TypeScript?

I think you understand what I mean, but I'll explain. For example, I have a UI directory and at its root there is an index.js file that contains exports from all components in this directory. And then I can do the import like this. Because ES6 by default looks for index.js in the folder if we try to import something from it. How can this be done with TypeScript? It turns out two problems - the index.js file is searched and not index.ts, but even if I make these index files in js, TypeScript will still highlight errors, because it does not understand such paths. What do you think about this?
import * as components from 'components/UI';


Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-06-11
@yarkov

all the same, TypeScript will highlight errors, because it does not understand such paths

Well, make sure you understand. In tsconfig.json set the option "moduleResolution": "node"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question