fix: Typegen handles structs and vectors of structs without erroring (#4743)

This commit is contained in:
Zannis Kalampoukis
2022-04-14 12:39:57 +03:00
committed by GitHub
parent 677d0c9969
commit 1aa2b7e1ff
2 changed files with 19 additions and 0 deletions
+17
View File
@@ -41,4 +41,21 @@ describe('getSimilarTypes', (): void => {
'Vec<Vec<Balance>>'
]);
});
it('handles structs', (): void => {
expect(getSimilarTypes(registry, {}, '{ "a": "u8", "b": "Vec<u8>" }', 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<H256>" }>', mockImports)).toEqual([
`Vec<{
readonly a: H256;
readonly b: Vec<H256>;
} & Struct>`
]);
});
});
+2
View File
@@ -60,6 +60,8 @@ export function getSimilarTypes (registry: Registry, definitions: Record<string,
possibleTypes.push(`([${subs.join(', ')}])[]`);
} else if (subDef.info === TypeDefInfo.VecFixed) {
// TODO: Add possibleTypes so imports work
} else if (subDef.info === TypeDefInfo.Struct) {
// TODO: Add possibleTypes so imports work
} else {
throw new Error(`Unhandled subtype in Vec, ${stringify(subDef)}`);
}