Replace usage of exportType in typegen (#4460)

This commit is contained in:
Jaco
2022-01-18 07:36:30 +02:00
committed by GitHub
parent d589adf208
commit da6311d584
3 changed files with 5 additions and 13 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ import staticPolkadot from '@polkadot/types-support/metadata/static-polkadot';
import staticSubstrate from '@polkadot/types-support/metadata/static-substrate';
import { isString, stringify } from '@polkadot/util';
import { createImports, exportType, initMeta, readTemplate, writeFile } from '../util';
import { createImports, exportInterface, initMeta, readTemplate, writeFile } from '../util';
import { typeEncoders } from './tsDef';
const WITH_TYPEDEF = false;
@@ -191,7 +191,7 @@ function generateLookupTypes (registry: Registry, filtered: [PortableType, TypeD
typeDef.name = typeDef.lookupName;
return typeDef.lookupNameRoot && typeDef.lookupName
? exportType(typeDef.lookupIndex, typeDef.lookupName, typeDef.lookupNameRoot)
? exportInterface(typeDef.lookupIndex, typeDef.lookupName, typeDef.lookupNameRoot)
: typeEncoders[typeDef.info](registry, imports.definitions, typeDef, imports);
}).filter((t): t is string => !!t);
+3 -3
View File
@@ -13,7 +13,7 @@ import * as defaultDefinitions from '@polkadot/types/interfaces/definitions';
import { getTypeDef, TypeDefInfo } from '@polkadot/types-create';
import { assert, isString, stringify, stringPascalCase } from '@polkadot/util';
import { createImports, exportInterface, exportType, formatType, readTemplate, setImports, TypeImports, writeFile } from '../util';
import { createImports, exportInterface, formatType, readTemplate, setImports, TypeImports, writeFile } from '../util';
interface Imports extends TypeImports {
interfaces: [string, string][];
@@ -204,11 +204,11 @@ function tsVec (registry: Registry, definitions: Record<string, ModuleTypes>, de
if (def.info === TypeDefInfo.VecFixed) {
setImports(definitions, imports, ['U8aFixed']);
return exportType(def.lookupIndex, def.name, 'U8aFixed');
return exportInterface(def.lookupIndex, def.name, 'U8aFixed');
} else {
setImports(definitions, imports, ['Bytes']);
return exportType(def.lookupIndex, def.name, 'Bytes');
return exportInterface(def.lookupIndex, def.name, 'Bytes');
}
}
-8
View File
@@ -109,14 +109,6 @@ export function exportInterface (lookupIndex = -1, name = '', base: string, body
return `${doc}export interface ${name} extends ${base} {${body.length ? '\n' : ''}${body}}`;
}
// helper to create an `export type <Name> = <Base>`
// but since we don't want type alias (TS doesn't preserve names) we use
// interface here.
/** @internal */
export function exportType (lookupIndex = -1, name = '', base: string): string {
return exportInterface(lookupIndex, name, base);
}
function singleParamNotation (registry: CodecRegistry, wrapper: string, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean): string {
const sub = (typeDef.sub as TypeDef);