// Initialize an empty Struct schema
let personSchema: S.Struct<{}> = S.struct({})
// Function to add fields iteratively using S.extend
function addField<A extends object, B extends object>(
schema: S.Struct<A>,
newFields: S.Struct<B>,
): S.Struct<A & B> {
return S.extend(schema, newFields)
}
// Add the 'name' field
personSchema = addField(personSchema, S.struct({
name: S.string
}))
// Add the 'age' field
personSchema = addField(personSchema, S.struct({
age: S.number
}))
// Initialize an empty Struct schema
let personSchema: S.Struct<{}> = S.struct({})
// Function to add fields iteratively using S.extend
function addField<A extends object, B extends object>(
schema: S.Struct<A>,
newFields: S.Struct<B>,
): S.Struct<A & B> {
return S.extend(schema, newFields)
}
// Add the 'name' field
personSchema = addField(personSchema, S.struct({
name: S.string
}))
// Add the 'age' field
personSchema = addField(personSchema, S.struct({
age: S.number
}))