react / react/metro

Add types for `require.context`

Open
#1,232 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5.6k
Forks
696
Avg merge
8m
Merged PRs (30d)
7

Description

Do you want to request a feature or report a bug?

Feature request

Currently, Metro supports require.context, added in this PR, but it lacks built-in type definitions. This makes it more challenging to use require.context effectively as there's no code completion, error checking, or refactoring support for its arguments.

Property 'context' does not exist on type 'NodeRequire'.
Screenshot 2024-03-08 at 15 17 28

Right now, I have to create a types file and add the following content from @EvanBacon's Metro-Context-Modules-Demo repo, having them included by default in Metro would be a great improvement.

Including type definitions for require.context would significantly improve the developer experience by enabling these features and making code using require.context more robust and maintainable.

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 type declaration in the linked Metro-Context-Modules-Demo repository at types/metroRequire.d.ts, then locate Metro’s existing built-in type definitions. Add the require.context definitions so its arguments receive completion, error checking, and refactoring support. Done means the reported NodeRequire error is resolved for Metro users.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.