Skip to content

Commit

Permalink
fix(plugin): use unknown to fix ts incompatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jul 5, 2023
1 parent 3b60994 commit 882722d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 7 additions & 5 deletions lib/compiler/interfaces/readonly-visitor.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export type DeepPluginMeta =
export interface ReadonlyVisitor {
key: string;
typeImports: Record<string, string>;
visit<Program = any, SourceFile = any>(
program: Program,
sf: SourceFile,
): void;
collect<MetaTuple = any>(): Record<string, Array<MetaTuple>>;

// Using unknown here because of the potential
// incompatibility between a locally installed TypeScript version
// and the one used by the CLI.

visit(program: unknown, sf: unknown): unknown;
collect(): Record<string, Array<unknown>>;
}
9 changes: 5 additions & 4 deletions lib/compiler/plugins/plugin-metadata-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ export class PluginMetadataGenerator {
) {
for (const sourceFile of programRef.getSourceFiles()) {
if (!sourceFile.isDeclarationFile) {
visitors.forEach((visitor) =>
visitor.visit<ts.Program, ts.SourceFile>(programRef, sourceFile),
);
visitors.forEach((visitor) => visitor.visit(programRef, sourceFile));
}
}

Expand All @@ -138,7 +136,10 @@ export class PluginMetadataGenerator {
> = {};

visitors.forEach((visitor) => {
collectedMetadata[visitor.key] = visitor.collect();
collectedMetadata[visitor.key] = visitor.collect() as Record<
string,
Array<[ts.CallExpression, DeepPluginMeta]>
>;
typeImports = {
...typeImports,
...visitor.typeImports,
Expand Down

0 comments on commit 882722d

Please sign in to comment.