Skip to content

Folders from typesRoot should be used in looking up for types for imports as well as @types folder #37958

@timocov

Description

@timocov

Search Terms

typesRoot, @types

Suggestion

typesRoot is folders you can specify where the compiler will looking up for types for modules without own types. But it looks like (according output with --traceResolution) it is used for /// <reference types directive, and isn't used to looking up modules when you import something. I think it'd be better to use it there as well.

Use Cases

For instance, you might have custom types folder with types for some packages (possible some packages has wrong declarations or even don't have them yet).

Examples

In the case above you can specify typesRoot to something like ["./custom-types","node_modules/@types"] and expect that the compiler will try to load types from custom-types folder if no typings exists in node_modules/@types.

Yeah, you can specify types option as well to load that type globally, but I'm not sure that loading every type globally is good idea.

As workaround right now you can "load" the types file with /// <reference types="type-name" /> and then import declared there modules (via declare module).

I'm not sure whether it's intended behaviour or not, but maybe we need to put some lights to the docs if so.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions