diff --git a/packages/compiler-cli/src/ngtsc/shims/src/host.ts b/packages/compiler-cli/src/ngtsc/shims/src/host.ts index 58a9d551b3f61..578ff10424c8e 100644 --- a/packages/compiler-cli/src/ngtsc/shims/src/host.ts +++ b/packages/compiler-cli/src/ngtsc/shims/src/host.ts @@ -39,11 +39,16 @@ export class GeneratedShimsHostWrapper implements ts.CompilerHost { (delegate.resolveTypeReferenceDirectives as ts3ResolveTypeReferenceDirectives) !( names, containingFile); } + if (delegate.directoryExists !== undefined) { + this.directoryExists = (directoryName: string) => delegate.directoryExists !(directoryName); + } } resolveTypeReferenceDirectives?: (names: string[], containingFile: string) => ts.ResolvedTypeReferenceDirective[]; + directoryExists?: (directoryName: string) => boolean; + getSourceFile( fileName: string, languageVersion: ts.ScriptTarget, onError?: ((message: string) => void)|undefined, diff --git a/packages/compiler-cli/test/ngtsc/env.ts b/packages/compiler-cli/test/ngtsc/env.ts index 54ecd951f8656..6fbf828c73d86 100644 --- a/packages/compiler-cli/test/ngtsc/env.ts +++ b/packages/compiler-cli/test/ngtsc/env.ts @@ -57,7 +57,6 @@ export class NgtscTestEnvironment { "skipLibCheck": true, "noImplicitAny": true, "strictNullChecks": true, - "types": [], "outDir": "built", "rootDir": ".", "baseUrl": ".", diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index 11a070e63c0e4..79192f1d0127a 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -1046,4 +1046,36 @@ describe('ngtsc behavioral tests', () => { }); }); }); + + it('should compile programs with typeRoots', () => { + // Write out a custom tsconfig.json that includes 'typeRoots' and 'files'. 'files' is necessary + // because otherwise TS picks up the testTypeRoot/test/index.d.ts file into the program + // automatically. Shims are also turned on (via allowEmptyCodegenFiles) because the shim + // ts.CompilerHost wrapper can break typeRoot functionality (which this test is meant to + // detect). + env.write('tsconfig.json', `{ + "extends": "./tsconfig-base.json", + "angularCompilerOptions": { + "allowEmptyCodegenFiles": true + }, + "compilerOptions": { + "typeRoots": ["./testTypeRoot"], + }, + "files": ["./test.ts"] + }`); + env.write('test.ts', ` + import {Test} from 'ambient'; + console.log(Test); + `); + env.write('testTypeRoot/.exists', ''); + env.write('testTypeRoot/test/index.d.ts', ` + declare module 'ambient' { + export const Test = 'This is a test'; + } + `); + + env.driveMain(); + + // Success is enough to indicate that this passes. + }); });