Skip to content

Commit

Permalink
fix(concatjs): resolve error with TypeScript 4.7 (#3420)
Browse files Browse the repository at this point in the history
In TypeScript 4.7 the first argument of `resolveTypeReferenceDirectives` can be a `FileReference[]`, in addition to a `string[]`. These changes resolve a runtime error that was happening as result.
  • Loading branch information
crisbeto authored Apr 22, 2022
1 parent 5d1c2ad commit 1074231
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/concatjs/internal/tsc_wrapped/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,32 +401,33 @@ export class CompilerHost implements ts.CompilerHost, tsickle.TsickleHost {
* typescript secondary search behavior needs to be overridden to support
* looking under `bazelOpts.nodeModulesPrefix`
*/
resolveTypeReferenceDirectives(names: string[], containingFile: string): ts.ResolvedTypeReferenceDirective[] {
resolveTypeReferenceDirectives(names: string[] | ts.FileReference[], containingFile: string): ts.ResolvedTypeReferenceDirective[] {
if (!this.allowActionInputReads) return [];
const result: ts.ResolvedTypeReferenceDirective[] = [];
names.forEach(name => {
const fileName = typeof name === 'string' ? name : name.fileName;
let resolved: ts.ResolvedTypeReferenceDirective | undefined;

// primary search
if (this.options.typeRoots) {
this.options.typeRoots.forEach(typeRoot => {
if (!resolved) {
resolved = this.resolveTypingFromDirectory(path.posix.join(typeRoot, name), true);
resolved = this.resolveTypingFromDirectory(path.posix.join(typeRoot, fileName), true);
}
});
}

// secondary search
if (!resolved) {
resolved = this.resolveTypingFromDirectory(path.posix.join(this.bazelOpts.nodeModulesPrefix, name), false);
resolved = this.resolveTypingFromDirectory(path.posix.join(this.bazelOpts.nodeModulesPrefix, fileName), false);
}

// Types not resolved should be silently ignored. Leave it to Typescript
// to either error out with "TS2688: Cannot find type definition file for
// 'foo'" or for the build to fail due to a missing type that is used.
if (!resolved) {
if (DEBUG) {
debug(`Failed to resolve type reference directive '${name}'`);
debug(`Failed to resolve type reference directive '${fileName}'`);
}
return;
}
Expand Down

0 comments on commit 1074231

Please sign in to comment.