Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
fix: Remove too narrow instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainTHD committed Oct 27, 2023
1 parent 0e60f3f commit 9ea5ead
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/typechecker/visitor/shared/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function visitUntypedFunction(
params.push({
name,
pType,
isGeneric: pType instanceof GenericType,
isGeneric: pType.isGeneric(),
isOptional,
});
}
Expand Down
4 changes: 4 additions & 0 deletions src/types/GenericType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class GenericType extends Type {
return this;
}

public override isGeneric(): boolean {
return true;
}

public static create(label: string, aliasType?: Type): GenericType {
return new GenericType(label, aliasType ?? UnknownType.create());
}
Expand Down
4 changes: 4 additions & 0 deletions src/types/Type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ export abstract class Type {
public replaceGenerics(_generics: { name: string; gType: Type }[]): Type {
return this;
}

public isGeneric(): boolean {
return false;
}
}
4 changes: 4 additions & 0 deletions src/types/UnionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export class UnionType extends Type {
return new UnionType(this.types.map((t) => t.replaceGenerics(generics))).simplify();
}

public override isGeneric(): boolean {
return this.types.some((t) => t.isGeneric());
}

public get size(): number {
return this.types.length;
}
Expand Down

0 comments on commit 9ea5ead

Please sign in to comment.