fix(compiler-cli): enable @types discovery in incremental rebuilds (#39011)
Prior to this fix, incremental rebuilds could fail to type check due to missing ambient types from auto-discovered declaration files in @types directories, or type roots in general. This was caused by the intermediary `ts.Program` that is created for template type checking, for which a `ts.CompilerHost` was used which did not implement the optional `directoryExists` methods. As a result, auto-discovery of types would not be working correctly, and this would retain into the `ts.Program` that would be created for an incremental rebuild. This commit fixes the issue by forcing the custom `ts.CompilerHost` used for type checking to properly delegate into the original `ts.CompilerHost`, even for optional methods. This is accomplished using a base class `DelegatingCompilerHost` which is typed in such a way that newly introduced `ts.CompilerHost` methods must be accounted for. Fixes #38979 PR Close #39011
This commit is contained in:
@ -442,6 +442,27 @@ runInEachFileSystem(() => {
|
||||
// https://github.com/angular/angular/issues/30079), this would have crashed.
|
||||
});
|
||||
|
||||
// https://github.com/angular/angular/issues/38979
|
||||
it('should retain ambient types provided by auto-discovered @types', () => {
|
||||
// This test verifies that ambient types declared in node_modules/@types are still available
|
||||
// in incremental compilations. In the below code, the usage of `require` should be valid
|
||||
// in the original program and the incremental program.
|
||||
env.tsconfig({fullTemplateTypeCheck: true});
|
||||
env.write('node_modules/@types/node/index.d.ts', 'declare var require: any;');
|
||||
env.write('main.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
require('path');
|
||||
|
||||
@Component({template: ''})
|
||||
export class MyComponent {}
|
||||
`);
|
||||
env.driveMain();
|
||||
env.invalidateCachedFile('main.ts');
|
||||
const diags = env.driveDiagnostics();
|
||||
expect(diags.length).toBe(0);
|
||||
});
|
||||
|
||||
// https://github.com/angular/angular/pull/26036
|
||||
it('should handle redirected source files', () => {
|
||||
env.tsconfig({fullTemplateTypeCheck: true});
|
||||
|
Reference in New Issue
Block a user