Skip to content

Commit 0838a67

Browse files
committed
fixup! Export type-predicates along when enumValues is true
1 parent 791ce53 commit 0838a67

File tree

1 file changed

+47
-51
lines changed

1 file changed

+47
-51
lines changed

packages/openapi-typescript/src/transform/schema-object.ts

+47-51
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ const createTypePredicateHelper = ts.factory.createFunctionDeclaration(
9292
/* modifiers */ undefined,
9393
/* name */ ts.factory.createIdentifier("TItem"),
9494
/* constraint */ tsUnion([NUMBER, STRING]),
95-
/* defaultType */ undefined
96-
)
95+
/* defaultType */ undefined,
96+
),
9797
],
9898
/* parameters */ [
9999
ts.factory.createParameterDeclaration(
@@ -106,12 +106,12 @@ const createTypePredicateHelper = ts.factory.createFunctionDeclaration(
106106
/* type */ ts.factory.createArrayTypeNode(
107107
/* elementType */ ts.factory.createTypeReferenceNode(
108108
/* typeName */ ts.factory.createIdentifier("TItem"),
109-
/* typeArguments */ undefined
110-
)
111-
)
109+
/* typeArguments */ undefined,
110+
),
111+
),
112112
),
113-
/* initializer */ undefined
114-
)
113+
/* initializer */ undefined,
114+
),
115115
],
116116
/* type */ undefined,
117117
/* body */ ts.factory.createBlock(
@@ -120,18 +120,20 @@ const createTypePredicateHelper = ts.factory.createFunctionDeclaration(
120120
ts.factory.createArrowFunction(
121121
/* modifiers */ undefined,
122122
/* typeParameters */ undefined,
123-
/* parameters */ [ts.factory.createParameterDeclaration(
124-
/* modifiers */ undefined,
125-
/* dotDotDotToken */ undefined,
126-
/* name */ ts.factory.createIdentifier("value"),
127-
/* questionToken */ undefined,
128-
/* type */ tsUnion([NULL, NUMBER, STRING, UNDEFINED]),
129-
/* initializer */ undefined
130-
)],
123+
/* parameters */ [
124+
ts.factory.createParameterDeclaration(
125+
/* modifiers */ undefined,
126+
/* dotDotDotToken */ undefined,
127+
/* name */ ts.factory.createIdentifier("value"),
128+
/* questionToken */ undefined,
129+
/* type */ tsUnion([NULL, NUMBER, STRING, UNDEFINED]),
130+
/* initializer */ undefined,
131+
),
132+
],
131133
/* type */ ts.factory.createTypePredicateNode(
132134
/* assertsModifier */ undefined,
133135
/* parameterName */ ts.factory.createIdentifier("value"),
134-
/* type */ ts.factory.createTypeReferenceNode("TItem")
136+
/* type */ ts.factory.createTypeReferenceNode("TItem"),
135137
),
136138
/* equalsGreaterThanToken */ ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
137139
/* body */ ts.factory.createBlock(
@@ -142,43 +144,43 @@ const createTypePredicateHelper = ts.factory.createFunctionDeclaration(
142144
/* left */ ts.factory.createBinaryExpression(
143145
/* left */ ts.factory.createIdentifier("value"),
144146
/* operator*/ ts.SyntaxKind.ExclamationEqualsEqualsToken,
145-
/* right */ ts.factory.createIdentifier("null")
147+
/* right */ ts.factory.createIdentifier("null"),
146148
),
147149
/* operator */ ts.SyntaxKind.AmpersandAmpersandToken,
148150
/* right */ ts.factory.createBinaryExpression(
149151
/* left */ ts.factory.createIdentifier("value"),
150152
/* operator */ ts.SyntaxKind.ExclamationEqualsEqualsToken,
151-
/* right */ ts.factory.createIdentifier("undefined")
152-
)
153+
/* right */ ts.factory.createIdentifier("undefined"),
154+
),
153155
),
154156
/* operator */ ts.SyntaxKind.AmpersandAmpersandToken,
155157
/* right */ ts.factory.createCallExpression(
156158
/* expression */ ts.factory.createPropertyAccessExpression(
157159
/* expression */ ts.factory.createIdentifier("items"),
158-
/* name */ ts.factory.createIdentifier("includes")
160+
/* name */ ts.factory.createIdentifier("includes"),
159161
),
160162
/* typeArguments */ undefined,
161163
/* argumentsArray */ [
162164
ts.factory.createAsExpression(
163165
/* expression */ ts.factory.createIdentifier("value"),
164166
/* type */ ts.factory.createTypeReferenceNode(
165167
/* typeName */ ts.factory.createIdentifier("TItem"),
166-
/* typeArguments */ undefined
167-
)
168-
)
169-
]
170-
)
171-
)
172-
)
168+
/* typeArguments */ undefined,
169+
),
170+
),
171+
],
172+
),
173+
),
174+
),
173175
],
174-
/* multiLine */ true
175-
)
176-
)
177-
)
176+
/* multiLine */ true,
177+
),
178+
),
179+
),
178180
],
179-
/* multiline */ true
180-
)
181-
)
181+
/* multiline */ true,
182+
),
183+
);
182184

183185
function getTypePredicate(constName: string, constTypeName: string, options: TransformNodeOptions) {
184186
if (!options.ctx.injectNodes.includes(createTypePredicateHelper)) {
@@ -195,20 +197,14 @@ function getTypePredicate(constName: string, constTypeName: string, options: Tra
195197
/* type */ undefined,
196198
/* initializer */ ts.factory.createCallExpression(
197199
/* expression */ ts.factory.createIdentifier("get_is"),
198-
/* typeArguments */ [
199-
ts.factory.createTypeReferenceNode(
200-
ts.factory.createIdentifier(constTypeName)
201-
)
202-
],
203-
/* argumentsArray */ [
204-
ts.factory.createIdentifier(constName)
205-
]
206-
)
207-
)
200+
/* typeArguments */ [ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(constTypeName))],
201+
/* argumentsArray */ [ts.factory.createIdentifier(constName)],
202+
),
203+
),
208204
],
209-
/* flags */ ts.NodeFlags.Const
210-
)
211-
)
205+
/* flags */ ts.NodeFlags.Const,
206+
),
207+
);
212208
}
213209

214210
function transformEnumSchemaObject(schemaObject: EnumSchemaObject, options: TransformNodeOptions) {
@@ -278,11 +274,11 @@ function transformEnumSchemaObject(schemaObject: EnumSchemaObject, options: Tran
278274
),
279275
)
280276
: undefined;
281-
277+
282278
const constTypePredicate =
283-
options.ctx.enumValues && constName && constTypeName ?
284-
getTypePredicate(constName, constTypeName, options)
285-
: undefined
279+
options.ctx.enumValues && constName && constTypeName
280+
? getTypePredicate(constName, constTypeName, options)
281+
: undefined;
286282

287283
// Add declarations for all selected output types.
288284
for (const node of [enumType, constExpression, constMemberType, constTypePredicate]) {

0 commit comments

Comments
 (0)