From 0ef082d4b474b7d36d7668cf21ad8a9922469189 Mon Sep 17 00:00:00 2001 From: "Marc J. Schmidt" Date: Wed, 28 Feb 2024 20:43:21 +0100 Subject: [PATCH] fix(type): better error message when fast path type resolution fails due to undefined symbols --- packages/type/src/reflection/reflection.ts | 16 ++++++++++++++-- packages/type/src/utils.ts | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/type/src/reflection/reflection.ts b/packages/type/src/reflection/reflection.ts index e907d867e..f5aff5229 100644 --- a/packages/type/src/reflection/reflection.ts +++ b/packages/type/src/reflection/reflection.ts @@ -50,7 +50,16 @@ import { TypePropertySignature, TypeTemplateLiteral, } from './type.js'; -import { AbstractClassType, arrayRemoveItem, ClassType, getClassName, isArray, isClass, isPrototypeOfBase, stringifyValueWithType } from '@deepkit/core'; +import { + AbstractClassType, + arrayRemoveItem, + ClassType, + getClassName, + isArray, + isClass, + isPrototypeOfBase, + stringifyValueWithType, +} from '@deepkit/core'; import { Packed, resolvePacked, resolveRuntimeType } from './processor.js'; import { NoTypeReceived } from '../utils.js'; import { findCommonLiteral } from '../inheritance.js'; @@ -85,7 +94,10 @@ export function resolveReceiveType(type?: Packed | Type | ClassType | AbstractCl //n! represents a simple inline: [Op.inline, 0] //P7! represents a class reference: [Op.Frame, Op.classReference, 0] (Op.Frame seems unnecessary) typeFn = (type as any)[0] as Function; - type = typeFn() as Packed | Type | ClassType | AbstractClassType | ReflectionClass; + type = typeFn() as Packed | Type | ClassType | AbstractClassType | ReflectionClass | undefined; + if (!type) { + throw new Error(`No type resolved for ${typeFn.toString()}. Circular import or no runtime type available.`); + } } } diff --git a/packages/type/src/utils.ts b/packages/type/src/utils.ts index 4204a1d50..2810b5807 100644 --- a/packages/type/src/utils.ts +++ b/packages/type/src/utils.ts @@ -11,8 +11,8 @@ import { stringify, v4 } from 'uuid'; export class NoTypeReceived extends Error { - constructor() { - super('No type information received. Is deepkit/type correctly installed?'); + constructor(message: string = 'No type information received. Circular import or no runtime type available.') { + super(message); } }