|
|
|
@ -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;
|
|
|
|
|