Skip to content

Commit

Permalink
fix(type): better error message when fast path type resolution fails …
Browse files Browse the repository at this point in the history
…due to undefined symbols
  • Loading branch information
marcj committed Feb 28, 2024
1 parent 38cfdf0 commit 0ef082d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions packages/type/src/reflection/reflection.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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<any>;
type = typeFn() as Packed | Type | ClassType | AbstractClassType | ReflectionClass<any> | undefined;
if (!type) {
throw new Error(`No type resolved for ${typeFn.toString()}. Circular import or no runtime type available.`);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/type/src/utils.ts
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 0ef082d

Please sign in to comment.