Skip to main content

SchemaFactoryAlpha Class

SchemaFactory with additional alpha APIs.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/tree/alpha.

For more information about our API support guarantees, see here.

Signature​

export declare class SchemaFactoryAlpha<out TScope extends string | undefined = string | undefined, TName extends number | string = string> extends SchemaFactoryBeta<TScope, TName>

Extends: SchemaFactoryBeta<TScope, TName>

Type Parameters​

ParameterConstraintDefaultDescription
TScopestring | undefinedstring | undefined
TNamenumber | stringstring

Static Properties​

PropertyAlertsModifiersTypeDescription
identifierAlphareadonly<const TCustomMetadata = unknown>(props?: Omit<FieldProps<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Identifier, import("../leafNodeSchema.js").StringSchema, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>Like identifier but static and a factory function that can be provided FieldProps.
leavesAlphareadonlyreadonly [import("../leafNodeSchema.js").StringSchema, LeafSchema<"number", number> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"boolean", boolean> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"null", null> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"handle", import("@fluidframework/core-interfaces").IFluidHandle<unknown>> & SimpleLeafNodeSchema<SchemaType>]AllowedTypes for holding any of the leaf types.
optionalAlphareadonly<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>Make a field optional instead of the default, which is required.
optionalRecursiveAlphareadonly<const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>optional except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.
requiredAlphareadonly<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>Make a field explicitly required.
requiredRecursiveAlphareadonly<const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>required except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.
stagedOptionalAlphareadonly<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>Creates a field schema that is Optional in the view but behaves as Required in the stored schema during the rollout period of an optional-field migration.
stagedOptionalRecursiveAlphareadonly<const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>stagedOptional except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.
withDefaultAlphareadonly<Kind extends FieldKind, Types extends ImplicitAllowedTypes, TCustomMetadata = unknown>(fieldSchema: FieldSchema<Kind, Types, TCustomMetadata>, defaultValue: NodeProvider<import("../fieldSchema.js").ApplyKindInput<import("../core/allowedTypes.js").InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind, true>>) => FieldSchemaAlpha<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }>Creates a field schema with a default value.
withDefaultRecursiveAlphareadonly<Kind extends FieldKind, Types extends System_Unsafe.ImplicitAllowedTypesUnsafe, TCustomMetadata = unknown>(fieldSchema: System_Unsafe.FieldSchemaUnsafe<Kind, Types, TCustomMetadata>, defaultValue: unknown) => FieldSchemaAlphaUnsafe<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }>Creates a field schema with a default value.

Properties​

PropertyAlertsModifiersTypeDescription
leavesAlphareadonlyreadonly [import("../leafNodeSchema.js").StringSchema, LeafSchema<"number", number> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"boolean", boolean> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"null", null> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"handle", import("@fluidframework/core-interfaces").IFluidHandle<unknown>> & SimpleLeafNodeSchema<SchemaType>]AllowedTypes for holding any of the leaf types.
optionalAlphareadonly<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>Make a field optional instead of the default, which is required.
optionalRecursiveAlphareadonly<const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>optional except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.
requiredAlphareadonly<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>Make a field explicitly required.
requiredRecursiveAlphareadonly<const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>required except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.
stagedOptionalAlphareadonly<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>Creates a field schema that is Optional in the view but behaves as Required in the stored schema during the rollout period of an optional-field migration.
stagedOptionalRecursiveAlphareadonly<const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>stagedOptional except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.
withDefaultAlphareadonly<Kind extends FieldKind, Types extends ImplicitAllowedTypes, TCustomMetadata = unknown>(fieldSchema: FieldSchema<Kind, Types, TCustomMetadata>, defaultValue: NodeProvider<import("../fieldSchema.js").ApplyKindInput<import("../core/allowedTypes.js").InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind, true>>) => FieldSchemaAlpha<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }>Creates a field schema with a default value.
withDefaultRecursiveAlphareadonly<Kind extends FieldKind, Types extends System_Unsafe.ImplicitAllowedTypesUnsafe, TCustomMetadata = unknown>(fieldSchema: System_Unsafe.FieldSchemaUnsafe<Kind, Types, TCustomMetadata>, defaultValue: unknown) => FieldSchemaAlphaUnsafe<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }>Creates a field schema with a default value.

Property Details​

identifier​

Like identifier but static and a factory function that can be provided FieldProps.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

static readonly identifier: <const TCustomMetadata = unknown>(props?: Omit<FieldProps<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Identifier, import("../leafNodeSchema.js").StringSchema, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const TCustomMetadata = unknown>(props?: Omit<FieldProps<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Identifier, import("../leafNodeSchema.js").StringSchema, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

leaves​

AllowedTypes for holding any of the leaf types.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

readonly leaves: readonly [import("../leafNodeSchema.js").StringSchema, LeafSchema<"number", number> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"boolean", boolean> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"null", null> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"handle", import("@fluidframework/core-interfaces").IFluidHandle<unknown>> & SimpleLeafNodeSchema<SchemaType>];

Type: readonly [import("../leafNodeSchema.js").StringSchema, LeafSchema<"number", number> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"boolean", boolean> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"null", null> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"handle", import("@fluidframework/core-interfaces").IFluidHandle<unknown>> & SimpleLeafNodeSchema<SchemaType>]

leaves​

AllowedTypes for holding any of the leaf types.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

static readonly leaves: readonly [import("../leafNodeSchema.js").StringSchema, LeafSchema<"number", number> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"boolean", boolean> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"null", null> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"handle", import("@fluidframework/core-interfaces").IFluidHandle<unknown>> & SimpleLeafNodeSchema<SchemaType>];

Type: readonly [import("../leafNodeSchema.js").StringSchema, LeafSchema<"number", number> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"boolean", boolean> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"null", null> & SimpleLeafNodeSchema<SchemaType>, LeafSchema<"handle", import("@fluidframework/core-interfaces").IFluidHandle<unknown>> & SimpleLeafNodeSchema<SchemaType>]

optional​

Make a field optional instead of the default, which is required.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

readonly optional: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

optional​

Make a field optional instead of the default, which is required.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

static readonly optional: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

optionalRecursive​

optional except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

readonly optionalRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

Remarks​

This version of optional has fewer type constraints to work around TypeScript limitations, see Unenforced. See ValidateRecursiveSchema for additional information about using recursive schema.

optionalRecursive​

optional except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

static readonly optionalRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

Remarks​

This version of optional has fewer type constraints to work around TypeScript limitations, see Unenforced. See ValidateRecursiveSchema for additional information about using recursive schema.

required​

Make a field explicitly required.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

readonly required: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

Remarks​

Fields are required by default, but this API can be used to make the required nature explicit in the schema, and allows associating custom properties with the field.

required​

Make a field explicitly required.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

static readonly required: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

Remarks​

Fields are required by default, but this API can be used to make the required nature explicit in the schema, and allows associating custom properties with the field.

requiredRecursive​

required except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

readonly requiredRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

Remarks​

This version of required has fewer type constraints to work around TypeScript limitations, see Unenforced. See ValidateRecursiveSchema for additional information about using recursive schema.

requiredRecursive​

required except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

static readonly requiredRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Required, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

Remarks​

This version of required has fewer type constraints to work around TypeScript limitations, see Unenforced. See ValidateRecursiveSchema for additional information about using recursive schema.

stagedOptional​

Creates a field schema that is Optional in the view but behaves as Required in the stored schema during the rollout period of an optional-field migration.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

readonly stagedOptional: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

Remarks​

Use this to incrementally migrate a required field to optional without a coordinated deployment. The migration path is:

  1. Start with sf.required(T) — all clients require the field. 2. Deploy sf.stagedOptional(T) — new clients can read documents where the field is present or absent, but the stored schema stays Required (so old clients are unaffected). Setting the field to undefined is rejected because the stored schema still declares the field as required. 3. Deploy sf.optional(T) once all clients support the staged optional field — the stored schema becomes Optional and the field can be cleared.

Analogous to staged for allowed types, but for field optionality.

stagedOptional​

Creates a field schema that is Optional in the view but behaves as Required in the stored schema during the rollout period of an optional-field migration.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

static readonly stagedOptional: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlpha<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

Remarks​

Use this to incrementally migrate a required field to optional without a coordinated deployment. The migration path is:

  1. Start with sf.required(T) — all clients require the field. 2. Deploy sf.stagedOptional(T) — new clients can read documents where the field is present or absent, but the stored schema stays Required (so old clients are unaffected). Setting the field to undefined is rejected because the stored schema still declares the field as required. 3. Deploy sf.optional(T) once all clients support the staged optional field — the stored schema becomes Optional and the field can be cleared.

Analogous to staged for allowed types, but for field optionality.

stagedOptionalRecursive​

stagedOptional except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

readonly stagedOptionalRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

Remarks​

This version of stagedOptional has fewer type constraints to work around TypeScript limitations, see Unenforced. See ValidateRecursiveSchema for additional information about using recursive schema.

stagedOptionalRecursive​

stagedOptional except tweaked to work better for recursive types. Use with ValidateRecursiveSchema for improved type safety.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

static readonly stagedOptionalRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>;

Type: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha<TCustomMetadata>, "stagedOptionalUpgrade" | "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe<FieldKind.Optional, T, TCustomMetadata, FieldPropsAlpha<TCustomMetadata>>

Remarks​

This version of stagedOptional has fewer type constraints to work around TypeScript limitations, see Unenforced. See ValidateRecursiveSchema for additional information about using recursive schema.

withDefault​

Creates a field schema with a default value.

This API is provided as an alpha preview and may change without notice.

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<import("../fieldSchema.js").ApplyKindInput<import("../core/allowedTypes.js").InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind, true>>) => FieldSchemaAlpha<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & {
defaultProvider: DefaultProvider;
}>;

Type: <Kind extends FieldKind, Types extends ImplicitAllowedTypes, TCustomMetadata = unknown>(fieldSchema: FieldSchema<Kind, Types, TCustomMetadata>, defaultValue: NodeProvider<import("../fieldSchema.js").ApplyKindInput<import("../core/allowedTypes.js").InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind, true>>) => FieldSchemaAlpha<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }>

Remarks​

Fields with defaults are optional in constructors, allowing them to be omitted when creating new nodes. This works with both required and optional fields:

  • **Required fields with defaults**: The field is always present in the tree, but can be omitted from the constructor. The default value is used when the field is not provided.
  • **Optional fields with defaults**: Optional fields already default to undefined, but withDefault lets you specify a different default value.

The default value can be provided in two ways (see NodeProvider):

  1. **A value**: The value is deep-copied for each use, ensuring independence between instances. Prefer this when the default is a fixed value.
  1. **A generator function**: A function called each time a default is needed. Use this for dynamic defaults (e.g., timestamps, UUIDs) or when explicit control over value creation is required.

Defaults are evaluated eagerly during node construction.

For recursive schemas, use withDefaultRecursive instead.

See the Default Field Values documentation for a comprehensive guide with additional examples.

withDefault​

Creates a field schema with a default value.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

static readonly withDefault: <Kind extends FieldKind, Types extends ImplicitAllowedTypes, TCustomMetadata = unknown>(fieldSchema: FieldSchema<Kind, Types, TCustomMetadata>, defaultValue: NodeProvider<import("../fieldSchema.js").ApplyKindInput<import("../core/allowedTypes.js").InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind, true>>) => FieldSchemaAlpha<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & {
defaultProvider: DefaultProvider;
}>;

Type: <Kind extends FieldKind, Types extends ImplicitAllowedTypes, TCustomMetadata = unknown>(fieldSchema: FieldSchema<Kind, Types, TCustomMetadata>, defaultValue: NodeProvider<import("../fieldSchema.js").ApplyKindInput<import("../core/allowedTypes.js").InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind, true>>) => FieldSchemaAlpha<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }>

Remarks​

Fields with defaults are optional in constructors, allowing them to be omitted when creating new nodes. This works with both required and optional fields:

  • **Required fields with defaults**: The field is always present in the tree, but can be omitted from the constructor. The default value is used when the field is not provided.
  • **Optional fields with defaults**: Optional fields already default to undefined, but withDefault lets you specify a different default value.

The default value can be provided in two ways (see NodeProvider):

  1. **A value**: The value is deep-copied for each use, ensuring independence between instances. Prefer this when the default is a fixed value.
  1. **A generator function**: A function called each time a default is needed. Use this for dynamic defaults (e.g., timestamps, UUIDs) or when explicit control over value creation is required.

Defaults are evaluated eagerly during node construction.

For recursive schemas, use withDefaultRecursive instead.

See the Default Field Values documentation for a comprehensive guide with additional examples.

withDefaultRecursive​

Creates a field schema with a default value.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

readonly withDefaultRecursive: <Kind extends FieldKind, Types extends System_Unsafe.ImplicitAllowedTypesUnsafe, TCustomMetadata = unknown>(fieldSchema: System_Unsafe.FieldSchemaUnsafe<Kind, Types, TCustomMetadata>, defaultValue: unknown) => 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: unknown) => FieldSchemaAlphaUnsafe<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }>

Remarks​

Fields with defaults are optional in constructors, allowing them to be omitted when creating new nodes. This works with both required and optional fields:

  • **Required fields with defaults**: The field is always present in the tree, but can be omitted from the constructor. The default value is used when the field is not provided.
  • **Optional fields with defaults**: Optional fields already default to undefined, but withDefault lets you specify a different default value.

The default value can be provided in two ways (see NodeProvider):

  1. **A value**: The value is deep-copied for each use, ensuring independence between instances. Prefer this when the default is a fixed value.
  1. **A generator function**: A function called each time a default is needed. Use this for dynamic defaults (e.g., timestamps, UUIDs) or when explicit control over value creation is required.

Defaults are evaluated eagerly during node construction.

For recursive schemas, use withDefaultRecursive instead.

See the Default Field Values documentation for a comprehensive guide with additional examples.

withDefaultRecursive​

Creates a field schema with a default value.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature​

static readonly withDefaultRecursive: <Kind extends FieldKind, Types extends System_Unsafe.ImplicitAllowedTypesUnsafe, TCustomMetadata = unknown>(fieldSchema: System_Unsafe.FieldSchemaUnsafe<Kind, Types, TCustomMetadata>, defaultValue: unknown) => 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: unknown) => FieldSchemaAlphaUnsafe<Kind, Types, TCustomMetadata, FieldPropsAlpha<TCustomMetadata> & { defaultProvider: DefaultProvider; }>

Remarks​

Fields with defaults are optional in constructors, allowing them to be omitted when creating new nodes. This works with both required and optional fields:

  • **Required fields with defaults**: The field is always present in the tree, but can be omitted from the constructor. The default value is used when the field is not provided.
  • **Optional fields with defaults**: Optional fields already default to undefined, but withDefault lets you specify a different default value.

The default value can be provided in two ways (see NodeProvider):

  1. **A value**: The value is deep-copied for each use, ensuring independence between instances. Prefer this when the default is a fixed value.
  1. **A generator function**: A function called each time a default is needed. Use this for dynamic defaults (e.g., timestamps, UUIDs) or when explicit control over value creation is required.

Defaults are evaluated eagerly during node construction.

For recursive schemas, use withDefaultRecursive instead.

See the Default Field Values documentation for a comprehensive guide with additional examples.