microsoft / microsoft/TypeScript

Support for directory named module

Open
#45,402 2 comments 18 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

When creating an application that follows atomic design, you usually want to create 1 folder per module, this folder containing both the tsx file and the scss file.

The issue is that, right now you're forced to either name your tsx files "index.tsx", so that you can import them using 'import "/path/to/DirectoryName"', but then it means that every single file module file in your project now have the same "index.tsx" name, which is a pain.

The other solution is to name your component files the same name as the folder, but now you have to specify the file name in the import. Exemple : 'import "/path/to/DirectoryName/DirectoryName".
But now you have import statements that are longer than needed, and it doesn't force you to name your tsx file correctly (unless you use CI), because it's not a default name anymore.

To have the best of both wold, we'd need for the default name to be either index.tsx or DirectoryName.tsx, so that we can do 'import "/path/to/DirectoryName"' to import /path/to/DirectoryName/DirectoryName.tsx

Webpack already supports this through this plugin : https://www.npmjs.com/package/directory-named-webpack-plugin (25k weekly downloads), so you can get an application that works using this kind of imports.

But the IDE's can't resolve the directory named imports, mostly because TS doesn't support it.

Adding support to this would be greatly appreciated.

This is been an issue for quite a long time, as been documented here : https://github.com/microsoft/TypeScript/issues/24116
This linked above issue also contains a proposed solution by @tylerkayser
@gaui 's comment summarizes that well : https://github.com/microsoft/TypeScript/issues/24116#issuecomment-399724546

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked TypeScript issue #24116 and the proposed solution in the referenced comment, then compare the requested behavior with the existing module-resolution design. Done means an import of a directory resolves its same-named TSX file without requiring the filename, while preserving the existing index.tsx behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.