diff --git a/src/NodeParser/IndexedAccessTypeNodeParser.ts b/src/NodeParser/IndexedAccessTypeNodeParser.ts index d7a481350..0a5445a06 100644 --- a/src/NodeParser/IndexedAccessTypeNodeParser.ts +++ b/src/NodeParser/IndexedAccessTypeNodeParser.ts @@ -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"; @@ -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( @@ -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; } diff --git a/src/NodeParser/TypeReferenceNodeParser.ts b/src/NodeParser/TypeReferenceNodeParser.ts index 14535a243..559260d5c 100644 --- a/src/NodeParser/TypeReferenceNodeParser.ts +++ b/src/NodeParser/TypeReferenceNodeParser.ts @@ -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 = { @@ -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. diff --git a/src/Type/UnknownType.ts b/src/Type/UnknownType.ts index 6cce276ff..78004074f 100644 --- a/src/Type/UnknownType.ts +++ b/src/Type/UnknownType.ts @@ -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; +}