Skip to content

Commit dfe5b53

Browse files
authored
chore: fix regression on object resolving (#18)
1 parent e2c5d98 commit dfe5b53

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/resolve.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ function retrieveTypeName (
2323
if (type.isArray()) {
2424
return `Array_${retrieveTypeName(type.getArrayElementType()!)}`
2525
}
26+
if (type.isIntersection()) {
27+
return `Intersection_${type.getIntersectionTypes().map(type => retrieveTypeName(type)).join('_')}`
28+
}
29+
if (type.isUnion()) {
30+
return `Union_${type.getUnionTypes().map(type => retrieveTypeName(type)).join('_')}`
31+
}
2632
const typeName = type.getSymbol()?.getName()
2733
if (typeof typeName === 'undefined') {
2834
return type.getText()
@@ -134,7 +140,9 @@ export function resolve (
134140
switch (helperName) {
135141
case 'Omit':
136142
case 'Pick':
137-
const args = typeArguments[1].getUnionTypes().map(t => capitalizeFirstLetter(String(t.getLiteralValue())))
143+
const args = typeArguments[1].isUnion()
144+
? typeArguments[1].getUnionTypes().map(t => capitalizeFirstLetter(String(t.getAliasSymbol()?.getName() ?? t.getLiteralValue())))
145+
: [capitalizeFirstLetter(String(typeArguments[1].getLiteralValue()))]
138146
typeName = `${retrieveTypeName(subjectType)}_With${helperName === 'Omit' ? 'out' : ''}_${args.join('_')}`
139147
break
140148
case 'Partial':
@@ -148,7 +156,7 @@ export function resolve (
148156
const subjectType = type.getTypeArguments()[0] ?? type.getAliasTypeArguments()[0]
149157
const name = type.getSymbol()?.getEscapedName() !== '__type' ? type.getSymbol()?.getEscapedName() : helperName
150158
typeName = `${name}_${retrieveTypeName(subjectType)}`
151-
} else if ((type.getAliasTypeArguments().length === 1 || type.getTypeArguments().length === 1)) { // i.e. Serialized<{ datasource: Datasource }> -> Serialized_datasource
159+
} else if ((type.getAliasTypeArguments().length === 1 || type.getTypeArguments().length === 1) && (type.getTypeArguments()[0] ?? type.getAliasTypeArguments()[0])?.isAnonymous() === true) { // i.e. Serialized<{ datasource: Datasource }> -> Serialized_datasource
152160
const subjectType = type.getTypeArguments()[0] ?? type.getAliasTypeArguments()[0]
153161
const name = type.getSymbol()?.getEscapedName() !== '__type' ? type.getSymbol()?.getEscapedName() : helperName
154162
typeName = `${name}_${retrieveTypeName(subjectType)}`

tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "./tsconfig.json",
3-
"exclude": ["tests", "example"]
3+
"exclude": ["tests", "example", "build"]
44
}

0 commit comments

Comments
 (0)