diff --git a/packages/type-compiler/src/compiler.ts b/packages/type-compiler/src/compiler.ts index eaa6e505a..d43d8a898 100644 --- a/packages/type-compiler/src/compiler.ts +++ b/packages/type-compiler/src/compiler.ts @@ -1895,8 +1895,23 @@ export class ReflectionTransformer implements CustomTransformer { if (isNodeWithLocals(current) && current.locals) { const found = current.locals.get(typeName.escapedText); if (found && found.declarations && found.declarations[0]) { - declaration = found.declarations[0]; - break; + /** + * Discard parameters, since they can not be referenced from inside + * + * ```typescript + * type B = string; + * function a(B: B) {} + * + * class A { + * constructor(B: B) {} + * } + * ``` + * + */ + if (!isParameter(found.declarations[0])) { + declaration = found.declarations[0]; + break; + } } } @@ -2622,7 +2637,6 @@ export class ReflectionTransformer implements CustomTransformer { * => function name() {}; name.__type = 34; */ protected decorateFunctionDeclaration(declaration: FunctionDeclaration) { - const encodedType = this.getTypeOfType(declaration); if (!encodedType) return declaration; diff --git a/packages/type-compiler/tests/transpile.spec.ts b/packages/type-compiler/tests/transpile.spec.ts index 44501722c..ed44d10e6 100644 --- a/packages/type-compiler/tests/transpile.spec.ts +++ b/packages/type-compiler/tests/transpile.spec.ts @@ -509,3 +509,30 @@ test('class typeName', () => { console.log(res.app); expect(res.app).toContain(`'StreamApiResponseClass'`); }); + +test('resolve type ref', () => { + const res = transpile({ + 'app': ` + class Guest {} + class Vehicle { + constructor(public Guest: Guest) { + } + } + ` + }); + console.log(res.app); + expect(res.app).toContain(`() => Guest, 'Guest'`); +}); + +test('resolve type ref2', () => { + const res = transpile({ + 'app': ` + class Guest {} + class Vehicle { + public Guest: Guest; + } + ` + }); + console.log(res.app); + expect(res.app).toContain(`() => Guest, 'Guest'`); +}); diff --git a/packages/type/tests/serializer.spec.ts b/packages/type/tests/serializer.spec.ts index 179c822fd..ad0ef6387 100644 --- a/packages/type/tests/serializer.spec.ts +++ b/packages/type/tests/serializer.spec.ts @@ -27,6 +27,7 @@ import { Reference, ReflectionKind, SignedBinaryBigInt, + stringifyResolvedType, Type, TypeProperty, TypePropertySignature, @@ -1373,3 +1374,19 @@ test("parcel search input deserialization", async () => { expect(search?.ad?.attributes?.buildingSurface).toBe(92); expect(search?.ad?.location.hasCoords()).toBeTruthy(); }); + +test('skip parameter name resolving', () => { + class Guest { + constructor(public id: number) { + } + } + + class Vehicle { + constructor(public Guest: Guest) { + } + } + + console.log(stringifyResolvedType(typeOf())); + + expect(cast({ Guest: { id: '1' } })).toEqual(new Vehicle(new Guest(1))); +});