Skip to content

Commit

Permalink
fixc
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Feb 17, 2025
1 parent 782ac82 commit 2fa0e6d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/NodeParser/IndexedAccessTypeNodeParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ts from "typescript";
import { LogicError } from "../Error/Errors.js";
import type { Context, NodeParser } from "../NodeParser.js";
import type { SubNodeParser } from "../SubNodeParser.js";
import type { BaseType } from "../Type/BaseType.js";
Expand All @@ -9,9 +10,9 @@ import { ReferenceType } from "../Type/ReferenceType.js";
import { StringType } from "../Type/StringType.js";
import { TupleType } from "../Type/TupleType.js";
import { UnionType } from "../Type/UnionType.js";
import { isErroredUnknownType } from "../Type/UnknownType.js";
import { derefType } from "../Utils/derefType.js";
import { getTypeByKey } from "../Utils/typeKeys.js";
import { LogicError } from "../Error/Errors.js";

export class IndexedAccessTypeNodeParser implements SubNodeParser {
public constructor(
Expand Down Expand Up @@ -49,7 +50,7 @@ export class IndexedAccessTypeNodeParser implements SubNodeParser {
const indexType = derefType(this.childNodeParser.createType(node.indexType, context));
const indexedType = this.createIndexedType(node.objectType, context, indexType);

if (indexedType) {
if (indexedType && !isErroredUnknownType(indexedType)) {
return indexedType;
}

Expand Down
3 changes: 2 additions & 1 deletion src/NodeParser/TypeReferenceNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AnyType } from "../Type/AnyType.js";
import { ArrayType } from "../Type/ArrayType.js";
import type { BaseType } from "../Type/BaseType.js";
import { StringType } from "../Type/StringType.js";
import { UnknownType } from "../Type/UnknownType.js";
import { symbolAtNode } from "../Utils/symbolAtNode.js";

const invalidTypes: Record<number, boolean> = {
Expand Down Expand Up @@ -45,7 +46,7 @@ export class TypeReferenceNodeParser implements SubNodeParser {
}

if (typeSymbol.flags & ts.SymbolFlags.TypeParameter) {
return context.getArgument(typeSymbol.name);
return context.getArgument(typeSymbol.name) || new UnknownType(true);
}

// Wraps promise type to avoid resolving to a empty Object type.
Expand Down
15 changes: 14 additions & 1 deletion src/Type/UnknownType.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { BaseType } from "./BaseType.js";

export class UnknownType extends BaseType {
constructor() {
constructor(
/**
* If the source for this UnknownType was from a failed operation than to an actual `unknown` type present in the source code.
*/
readonly erroredSource = false,
) {
super();
}

public getId(): string {
return "unknown";
}
}

/**
* Checks for an UnknownType with an errored source.
*/
export function isErroredUnknownType(type: BaseType): type is UnknownType {
return type instanceof UnknownType && type.erroredSource;
}

0 comments on commit 2fa0e6d

Please sign in to comment.