We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent de9792f commit bc4d34dCopy full SHA for bc4d34d
packages/openapi-typescript/src/utils.ts
@@ -180,9 +180,17 @@ export function tsNonNullable(type: string): string {
180
return `NonNullable<${type}>`;
181
}
182
183
-/** OneOf<T> (custom) */
+/**
184
+ * OneOf<T>
185
+ * TypeScript unions are not exclusive @see https://stackoverflow.com/questions/42123407/does-typescript-support-mutually-exclusive-types
186
+ * However, at a certain size, the helper type becomes to complex for inference to work. Hence the > check.
187
+ */
188
export function tsOneOf(...types: string[]): string {
- if (types.length === 1) return types[0];
189
+ if (types.length === 1) {
190
+ return types[0];
191
+ } else if (types.length > 5) {
192
+ return tsUnionOf(...types);
193
+ }
194
return `OneOf<[${types.join(", ")}]>`;
195
196
0 commit comments