-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeCommittedThe team has roadmapped this issueThe team has roadmapped this issueFix AvailableA PR has been opened for this issueA PR has been opened for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
Today, baseUrl performs two functions:
- it acts as a prefix for all entries in
paths - it acts as a potential resolution point for all bare paths
But almost nobody realizes that last part. It means if you have the following:
{
"compilerOptions": {
// ...
"baseUrl": "./src",
"paths": {
"@app/*": ["app/*"],
"@lib/*": ["lib/*"]
}
}
}An import like
import * as blah from "blah.js";might resolve to any of the following paths
./src/app/blah.js./src/lib/blah.js./src/blah.js⚠️
That last resolution is usually undesirable. Often though, people specify a baseUrl because it was previously required to make paths work.
In TypeScript 7.0, we are not reimplementing baseUrl.
Instead, paths will need to manually specify a custom prefix.
{
"compilerOptions": {
// ...
- "baseUrl": "./src",
"paths": {
- "@app/*": ["app/*"],
- "@lib/*": ["lib/*"]
+ "@app/*": ["./src/app/*"],
+ "@lib/*": ["./src/lib/*"]
}
}
}In the event that you want to maintain the same behavior as before, you can add an additional path mapping for the baseUrl itself:
{
"compilerOptions": {
// ...
"paths": {
// A new catch-all that replaces the baseUrl:
"*": ["./src/*"],
// Every other path now has an explicit common prefix:
"@app/*": ["./src/app/*"],
"@lib/*": ["./src/lib/*"],
}
}
}In TypeScript 6.0, we will be deprecating this behavior. Using baseUrl will lead to an error which can only be resolved by applying one of the above fixes, or using --ignoreDeprecations.
kirkwaiblinger, styfle, aleksei-berezkin, BCAPATHSHALA, Proallone and 1 moreCopilot and oliviertassinari
Metadata
Metadata
Assignees
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeCommittedThe team has roadmapped this issueThe team has roadmapped this issueFix AvailableA PR has been opened for this issueA PR has been opened for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript