Skip to content

Commit 334f806

Browse files
Make tsIntersectionOf a bit more robust for edge cases
1 parent c559d47 commit 334f806

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/utils.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,10 @@ export function tsArrayOf(type: string): string {
157157

158158
/** X & Y & Z; */
159159
export function tsIntersectionOf(...types: string[]): string {
160+
types = types.filter((t) => t !== "unknown");
161+
if (types.length === 0) return "unknown";
160162
if (types.length === 1) return String(types[0]); // don’t add parentheses around one thing
161-
return types
162-
.filter((t) => t !== "unknown")
163-
.map((t) => (TS_UNION_INTERSECTION_RE.test(t) ? `(${t})` : t))
164-
.join(" & ");
163+
return types.map((t) => (TS_UNION_INTERSECTION_RE.test(t) ? `(${t})` : t)).join(" & ");
165164
}
166165

167166
/** NonNullable<T> */

0 commit comments

Comments
 (0)