@@ -100,7 +100,11 @@ export class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer {
100100 return [ "S.optional(" , this . typeMapTypeFor ( p . type ) , ")" ] ;
101101 }
102102
103- private typeMapTypeFor ( t : Type , required = true ) : Sourcelike {
103+ private typeMapTypeFor (
104+ t : Type ,
105+ required = true ,
106+ coerceStrings = false ,
107+ ) : Sourcelike {
104108 if ( t . kind === "class" || t . kind === "object" || t . kind === "enum" ) {
105109 const name = this . nameForNamedType ( t ) ;
106110 if ( this . emittedObjects . has ( name ) ) {
@@ -143,6 +147,7 @@ export class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer {
143147 ( _enumType ) => panic ( "Should already be handled." ) ,
144148 ( unionType ) => {
145149 const types = Array . from ( unionType . getChildren ( ) ) ;
150+ const coerce = types . some ( ( type ) => type . kind === "bool" ) ;
146151 const rank = ( type : Type ) : number =>
147152 type . kind === "class" || type . kind === "object" ? 1 : 0 ;
148153 types . sort ( ( a , b ) => rank ( a ) - rank ( b ) ) ;
@@ -152,7 +157,7 @@ export class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer {
152157 if ( type . kind === "null" ) {
153158 nullable = true ;
154159 } else {
155- children . push ( this . typeMapTypeFor ( type , false ) ) ;
160+ children . push ( this . typeMapTypeFor ( type , false , coerce ) ) ;
156161 }
157162 }
158163
@@ -167,6 +172,10 @@ export class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer {
167172 ] ;
168173 } ,
169174 ( _transformedStringType ) => {
175+ if ( _transformedStringType . kind === "bool-string" )
176+ return coerceStrings
177+ ? 'S.transform(S.Literal("true", "false"), S.Boolean, { strict: true, decode: (value) => value === "true", encode: (value) => value ? "true" : "false" })'
178+ : 'S.Literal("true", "false")' ;
170179 return "S.String" ;
171180 } ,
172181 ) ;
0 commit comments