diff --git a/npm/ng-packs/packages/schematics/src/utils/type.ts b/npm/ng-packs/packages/schematics/src/utils/type.ts index d6e451f202..9734b96af5 100644 --- a/npm/ng-packs/packages/schematics/src/utils/type.ts +++ b/npm/ng-packs/packages/schematics/src/utils/type.ts @@ -15,13 +15,18 @@ export function createTypeSimplifier() { ); return type.split('.').pop()!; }); - return (type: string) => parseType(type).join(' | '); + + return (type: string) => { + const parsed = parseType(type); + const last = parsed.pop()!; + return parsed.reduceRight((record, tKey) => `Record<${tKey}, ${record}>`, last); + }; } export function createTypeParser(replacerFn = (t: string) => t) { const normalizeType = createTypeNormalizer(replacerFn); - return (originalType: string) => flattenUnionTypes([], originalType).map(normalizeType); + return (originalType: string) => flattenDictionaryTypes([], originalType).map(normalizeType); } export function createTypeNormalizer(replacerFn = (t: string) => t) { @@ -32,14 +37,10 @@ export function createTypeNormalizer(replacerFn = (t: string) => t) { }; } -export function flattenUnionTypes(types: string[], type: string) { +export function flattenDictionaryTypes(types: string[], type: string) { type - .replace(/^{/, '') - .replace(/}$/, '') - .replace(/{/, '(') - .replace(/}/, ')') + .replace(/[}{]/g, '') .split(':') - .filter(Boolean) .forEach(t => types.push(t)); return types;