diff --git a/npm/ng-packs/packages/schematics/src/utils/type.ts b/npm/ng-packs/packages/schematics/src/utils/type.ts index 781794c463..1c7eda81bb 100644 --- a/npm/ng-packs/packages/schematics/src/utils/type.ts +++ b/npm/ng-packs/packages/schematics/src/utils/type.ts @@ -1,7 +1,7 @@ -import { SYSTEM_TYPES } from '../constants'; -import { VOLO_REGEX } from '../constants/volo'; +import { SYSTEM_TYPES, VOLO_REGEX } from '../constants'; import { eImportKeyword } from '../enums'; import { Import, TypeWithEnum } from '../models'; +import { extractSimpleGenerics } from './generics'; import { parseNamespace } from './namespace'; import { relativePathToEnum, relativePathToModel } from './path'; import { parseGenerics } from './tree'; @@ -15,14 +15,9 @@ export function createTypeSimplifier() { type = /any.+)<.*(?<=[\.<])(?.+)>/gm); - const { generic, genericType } = regexp.exec(type)?.groups ?? {}; + const { identifier, generics } = extractSimpleGenerics(type); - return generic - ? generic === 'any' - ? 'any' - : `${generic}<${genericType}>` - : type.split('.').pop()!; + return generics.length ? `${identifier}<${generics.join(', ')}>` : identifier; }); return (type: string) => { @@ -40,9 +35,7 @@ export function createTypeParser(replacerFn = (t: string) => t) { export function createTypeNormalizer(replacerFn = (t: string) => t) { return (type: string) => { - type = normalizeTypeAnnotations(type); - - return replacerFn(type); + return replacerFn(normalizeTypeAnnotations(type)); }; } @@ -56,8 +49,7 @@ export function flattenDictionaryTypes(types: string[], type: string) { } export function normalizeTypeAnnotations(type: string) { - type = type.replace(/\[(.+)+\]/g, '$1[]'); - return type.replace(/\?/g, ''); + return type.replace(/\[(.+)+\]/g, '$1[]').replace(/\?/g, ''); } export function removeGenerics(type: string) {