From 1aa2b7e1ff5bae6459e1ab0bc03dd46ebbfd3de2 Mon Sep 17 00:00:00 2001 From: Zannis Kalampoukis Date: Thu, 14 Apr 2022 12:39:57 +0300 Subject: [PATCH] fix: Typegen handles structs and vectors of structs without erroring (#4743) --- packages/typegen/src/util/derived.spec.ts | 17 +++++++++++++++++ packages/typegen/src/util/derived.ts | 2 ++ 2 files changed, 19 insertions(+) diff --git a/packages/typegen/src/util/derived.spec.ts b/packages/typegen/src/util/derived.spec.ts index 1600b72387..171a6aa2da 100644 --- a/packages/typegen/src/util/derived.spec.ts +++ b/packages/typegen/src/util/derived.spec.ts @@ -41,4 +41,21 @@ describe('getSimilarTypes', (): void => { 'Vec>' ]); }); + + it('handles structs', (): void => { + expect(getSimilarTypes(registry, {}, '{ "a": "u8", "b": "Vec" }', mockImports)).toEqual([ + `{ + readonly a: u8; + readonly b: Bytes; + } & Struct`, '{ a?: any; b?: any }', 'string', 'Uint8Array' + ]); + }); + it('handles vectors of structs', (): void => { + expect(getSimilarTypes(registry, {}, 'Vec<{ "a": "H256", "b": "Vec" }>', mockImports)).toEqual([ + `Vec<{ + readonly a: H256; + readonly b: Vec; + } & Struct>` + ]); + }); }); diff --git a/packages/typegen/src/util/derived.ts b/packages/typegen/src/util/derived.ts index eea8d0f9e0..a93b6b4823 100644 --- a/packages/typegen/src/util/derived.ts +++ b/packages/typegen/src/util/derived.ts @@ -60,6 +60,8 @@ export function getSimilarTypes (registry: Registry, definitions: Record