-
Notifications
You must be signed in to change notification settings - Fork 1.4k
More precise descriptions of project reference-related editor options. #3384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
--- | ||
display: "Disable Referenced Project Load" | ||
oneline: "Reduce the number of projects loaded automatically by TypeScript." | ||
oneline: "Avoid searching for symbols across referenced projects in code editors." | ||
--- | ||
|
||
In multi-project TypeScript programs, TypeScript will load all of the available projects into memory in order to provide accurate results for editor responses which require a full knowledge graph like 'Find All References'. | ||
In multi-project TypeScript programs, TypeScript will load all referenced projects into memory in order to provide accurate results for editor responses which require a full knowledge graph like *Find all References* and *Rename*. | ||
|
||
If your project is large, you can use the flag `disableReferencedProjectLoad` to avoid loading referenced projects to answer these questions. | ||
Instead, referenced projects will only be searched if files of the referenced projects are already open in the editor. | ||
|
||
If your project is large, you can use the flag `disableReferencedProjectLoad` to disable the automatic loading of all projects. Instead, projects are loaded dynamically as you open files through your editor. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,49 @@ | ||
--- | ||
display: "Disable Source Project Reference Redirect" | ||
oneline: "Disable preferring source files instead of declaration files when referencing composite projects." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC the onelines come from the CLI flag descriptions, if that matters to you. |
||
display: "Disable Redirections to Project Reference Source Files" | ||
oneline: "When editing code, only consult declaration files from referenced projects." | ||
--- | ||
|
||
When working with [composite TypeScript projects](/docs/handbook/project-references.html), this option provides a way to go [back to the pre-3.7](/docs/handbook/release-notes/typescript-3-7.html#build-free-editing-with-project-references) behavior where d.ts files were used to as the boundaries between modules. | ||
In 3.7 the source of truth is now your TypeScript files. | ||
When editing a project with [project references](/docs/handbook/project-references.html), the TypeScript language service does not require us to build all dependencies so that generated declaration files are available. | ||
This is subtle, because this behavior means things usually "just work" in the editor, but differs from how project reference builds work, and warrants explanation. | ||
|
||
When building project references, the compiler always expects declaration files to be generated so that less code can be held in memory at once. | ||
This behavior works for performing a full build, but is often confusing when editing code. | ||
When referencing code from another project, most people expect the changes to be available immediately in the editor. | ||
|
||
For example, imagine making the following change to `projectB/src/setColor.ts` | ||
|
||
```diff ts | ||
export Options { | ||
hue: number; | ||
saturation: number; | ||
- value: number; | ||
+ lightness: number; | ||
} | ||
|
||
export function setColor(options: Options): void { | ||
// ... | ||
} | ||
``` | ||
|
||
If we want to update `projectA/src/draw.ts` to call `setColor` with `lightness` instead of `value` as so: | ||
|
||
```diff ts | ||
function draw() { | ||
// ... | ||
setColor({ | ||
hue: getUserSetting("hue"), | ||
saturation: getUserSetting("saturation"), | ||
- value: getUserSetting("value"), | ||
+ lightness: getUserSetting("lightness"), | ||
}) | ||
} | ||
``` | ||
|
||
we don't want to stop what we're doing and build `projectB` before we can get accurate errors in `projectA`, so TypeScript prefers reading source `.ts` files instead of generated `.d.ts` files if they're around. | ||
|
||
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we always get source file even if project is not yet built and hence no d.ts file |
||
This behavior makes editing easier, but comes at a cost. | ||
Each file has to be resolved back to its source, and that source will likely take longer to parse and type-check than the expected declaration files. | ||
In larger codebases, this extra work can feel very slow. | ||
|
||
The `disableSourceOfProjectReferenceRedirect` option allows developers to opt out of loading source files over declaration files in the editor ([just as it worked before TypeScript 3.7](/docs/handbook/release-notes/typescript-3-7.html#build-free-editing-with-project-references)). | ||
As a result, dependencies will need to be build with declaration files in order to get accurate error-checking, code completion, and other editor features in a project with references. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And with declarationMap if you want the definition to jump to original source file instead of d.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also stops loading reference projects and looking up in it for default project for file.