Skip to content

Commit 0a52b71

Browse files
committed
fmt
1 parent 50f0934 commit 0a52b71

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

packages/schema-generator/src/type-utils.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export function safeGetPropertyType(
8383
const propSymbol = checker.getPropertyOfType(parentType, propName);
8484
if (propSymbol) {
8585
typeFromParent = checker.getTypeOfSymbol(propSymbol);
86-
const typeStr = typeFromParent ? checker.typeToString(typeFromParent) : undefined;
86+
const typeStr = typeFromParent
87+
? checker.typeToString(typeFromParent)
88+
: undefined;
8789
// If we got 'any', treat it as if we didn't get a type
8890
if (typeStr === "any") {
8991
typeFromParent = undefined;
@@ -115,11 +117,13 @@ export function safeGetPropertyType(
115117
// Check if parent is a union that contains undefined, and if removing it gives us the decl type
116118
if (isOptional && typeFromParent.isUnion()) {
117119
const parentUnion = typeFromParent as ts.UnionType;
118-
const hasUndefined = parentUnion.types.some(t => !!(t.flags & ts.TypeFlags.Undefined));
120+
const hasUndefined = parentUnion.types.some((t) =>
121+
!!(t.flags & ts.TypeFlags.Undefined)
122+
);
119123

120124
if (hasUndefined) {
121125
const nonUndefinedTypes = parentUnion.types.filter(
122-
t => !(t.flags & ts.TypeFlags.Undefined)
126+
(t) => !(t.flags & ts.TypeFlags.Undefined),
123127
);
124128

125129
// Compare the non-undefined part with the declaration type
@@ -133,8 +137,12 @@ export function safeGetPropertyType(
133137
} else if (nonUndefinedTypes.length > 1) {
134138
// Multiple non-undefined types - check if decl is also a union with the same types
135139
// For now, just check string equality which should work for most cases
136-
const withoutUndefinedStr = nonUndefinedTypes.map(t => checker.typeToString(t)).join(" | ");
137-
if (withoutUndefinedStr === declStr || declStr === withoutUndefinedStr) {
140+
const withoutUndefinedStr = nonUndefinedTypes.map((t) =>
141+
checker.typeToString(t)
142+
).join(" | ");
143+
if (
144+
withoutUndefinedStr === declStr || declStr === withoutUndefinedStr
145+
) {
138146
return typeFromDecl;
139147
}
140148
}
@@ -154,7 +162,7 @@ export function safeGetPropertyType(
154162
if (isOptional && typeFromParent.isUnion()) {
155163
const unionType = typeFromParent as ts.UnionType;
156164
const nonUndefinedTypes = unionType.types.filter(
157-
t => !(t.flags & ts.TypeFlags.Undefined)
165+
(t) => !(t.flags & ts.TypeFlags.Undefined),
158166
);
159167
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]) {
160168
return nonUndefinedTypes[0];

packages/schema-generator/test/schema/record-mapped-types.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ describe("Schema: Record and mapped types", () => {
253253
const schema = transformer(type, checker, typeNode);
254254

255255
console.log("box schema:", JSON.stringify(schema.properties?.box));
256-
console.log("explicitBox schema:", JSON.stringify(schema.properties?.explicitBox));
256+
console.log(
257+
"explicitBox schema:",
258+
JSON.stringify(schema.properties?.explicitBox),
259+
);
257260
console.log("$defs keys:", Object.keys(schema.$defs || {}));
258261

259262
// Box without explicit param uses default (string)

0 commit comments

Comments
 (0)