Auto import improvement for directory. #46134
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Domain: Auto-import
Suggestion
An idea for TypeScript
Suggestion
I have many components in my project, like:
When auto importing
Button
ina.tsx
.Expected behavior
import {Button} from "./components/button";
Actual behavior
import {Button} from "./components/button/button";
import {Button} from "./components/";
When import
button/index.ts
, TS will omitindex
and usebutton
automatically, but custom index file is not supported, through they can be loaded by specifyingmain
/types
field ofpackage.json
.One workaround is to rename all components to
index.tsx
, but it is a bad practice for two reasons:index.tsx
in source section.index.tsx
.In addition, TS do not support multiple
*
and RegExp inpaths
oftsconfig.json
,I cannot write paths like:
I have to add a 'package.json' to each component folder which only contains one line:
{"main": "./<dirname>.tsx"}
, which is too verbose.components/index.ts
re-exports all components in this directory. It is designed for users outside of this project.I prefer direct exports over re-exports in
components
directory. (Mixed: #45015, #43777)🔍 Search Terms
auto import shortest directory
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Auto-import feature improvement for best practise.
📃 Motivating Example
💻 Use Cases
The text was updated successfully, but these errors were encountered: