SchemaStaticsAlpha Interface
Stateless APIs exposed via SchemaFactoryBeta as both instance properties and as statics.
For more information about our API support guarantees, see here.
This type is "sealed," meaning that code outside of the library defining it should not implement or extend it. Future versions of this type may add members or make typing of readonly members more specific.
Signature
/** @sealed */
export interface SchemaStaticsAlpha
Properties
| Property | Alerts | Modifiers | Type | Description |
|---|---|---|---|---|
| withDefault | Alpha | readonly | <Kind extends FieldKind, Types extends ImplicitAllowedTypes, TCustomMetadata = unknown>(fieldSchema: FieldSchema<Kind, Types, TCustomMetadata>, defaultValue: NodeProvider<InsertableTreeFieldFromImplicitField<FieldSchema<Kind, Types>>>) => FieldSchemaAlpha<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }> | Creates a field schema with a default value. Fields with defaults (whether required or optional) are recognized by the type system as optional in constructors, allowing them to be omitted when creating new nodes. |
| withDefaultRecursive | Alpha | <Kind extends FieldKind, Types extends System_Unsafe.ImplicitAllowedTypesUnsafe, TCustomMetadata = unknown>(fieldSchema: System_Unsafe.FieldSchemaUnsafe<Kind, Types, TCustomMetadata>, defaultValue: Unenforced<NodeProvider<System_Unsafe.InsertableTreeFieldFromImplicitFieldUnsafe<System_Unsafe.FieldSchemaUnsafe<Kind, Types>>>>) => FieldSchemaAlphaUnsafe<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }> | withDefault except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety. |
Property Details
withDefault
Creates a field schema with a default value. Fields with defaults (whether required or optional) are recognized by the type system as optional in constructors, allowing them to be omitted when creating new nodes.
For more information about our API support guarantees, see here.
Signature
readonly withDefault: <Kind extends FieldKind, Types extends ImplicitAllowedTypes, TCustomMetadata = unknown>(fieldSchema: FieldSchema<Kind, Types, TCustomMetadata>, defaultValue: NodeProvider<InsertableTreeFieldFromImplicitField<FieldSchema<Kind, Types>>>) => FieldSchemaAlpha<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & {
defaultProvider: DefaultProvider;
}>;
Type: <Kind extends FieldKind, Types extends ImplicitAllowedTypes, TCustomMetadata = unknown>(fieldSchema: FieldSchema<Kind, Types, TCustomMetadata>, defaultValue: NodeProvider<InsertableTreeFieldFromImplicitField<FieldSchema<Kind, Types>>>) => FieldSchemaAlpha<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }>
Example
const MySchema = factory.objectAlpha("MyObject", {
// Provide values directly
name: factory.withDefault(factory.required(factory.string), "untitled"),
count: factory.withDefault(factory.required(factory.number), 0),
metadata: factory.withDefault(factory.optional(Metadata), new Metadata({ version: 1 })),
// Use generator functions for dynamic values
timestamp: factory.withDefault(factory.required(factory.number), () => Date.now()),
id: factory.withDefault(factory.required(factory.string), () => crypto.randomUUID()),
});
const obj1 = new MySchema({}); // All defaults applied
const obj2 = new MySchema({ name: "custom" }); // name="custom", other defaults applied
withDefaultRecursive
withDefault except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.
For more information about our API support guarantees, see here.
Signature
withDefaultRecursive: <Kind extends FieldKind, Types extends System_Unsafe.ImplicitAllowedTypesUnsafe, TCustomMetadata = unknown>(fieldSchema: System_Unsafe.FieldSchemaUnsafe<Kind, Types, TCustomMetadata>, defaultValue: Unenforced<NodeProvider<System_Unsafe.InsertableTreeFieldFromImplicitFieldUnsafe<System_Unsafe.FieldSchemaUnsafe<Kind, Types>>>>) => FieldSchemaAlphaUnsafe<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & {
defaultProvider: DefaultProvider;
}>;
Type: <Kind extends FieldKind, Types extends System_Unsafe.ImplicitAllowedTypesUnsafe, TCustomMetadata = unknown>(fieldSchema: System_Unsafe.FieldSchemaUnsafe<Kind, Types, TCustomMetadata>, defaultValue: Unenforced<NodeProvider<System_Unsafe.InsertableTreeFieldFromImplicitFieldUnsafe<System_Unsafe.FieldSchemaUnsafe<Kind, Types>>>>) => FieldSchemaAlphaUnsafe<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }>
Remarks
This version of withDefault has fewer type constraints to work around TypeScript limitations, see Unenforced. See ValidateRecursiveSchema for additional information about using recursive schema.
See Also
SchemaStatics for why this is useful.