Skip to content

Conversation

@arendjr
Copy link
Contributor

@arendjr arendjr commented May 20, 2025

Summary

Another step to more TypeScript-like import handling: We implement the ability to resolve type definitions, which is now the preferred mechanism for the resolver in our module graph. This means we respect tsconfig.json's compilerOptions.typeRoots field and search the directories specified there for type definitions. If it's not set, we default to looking inside node_modules/@types directories. In either case, if type definitions cannot be found, we fall back to regular dependency handling.

I think this means we may discover .js files in places TypeScript would bail, but that may be a feature rather than a bug. If it gives trouble, we can always revise that.

In practice, I don't expect this PR to have much influence on our type inference, since our inference doesn't support .d.ts that well yet, so that will be the next step.

PS.: The huge line count is due to a React .d.ts I checked in. Maybe it's overkill, but I think I want to use that file later for seeing how well our .d.ts handling works :)

Test Plan

Test cases added.

@arendjr arendjr requested review from a team May 20, 2025 11:22
@github-actions github-actions bot added the A-Project Area: project label May 20, 2025
@arendjr arendjr moved this to In review in Type Inference May 20, 2025
@arendjr arendjr merged commit 121a774 into biomejs:main May 20, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in Type Inference May 20, 2025
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lot of great documentation, thank you

];

pub const SUPPORTED_TYPE_EXTENSIONS: &[&str] = &[
"d.ts", "d.mts", "d.cts", "js", "jsx", "mjs", "cjs", "ts", "tsx", "mts", "cts", "json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is json there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's also in the regular SUPPORTED_EXTENSIONS, and I figured who knows, maybe we could derive a literal type from such files one day :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Project Area: project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants