createAssetValidator

See source code

Create a validator for an asset record type.

function createAssetValidator<Type extends string, Props extends JsonObject>(
  type: Type,
  props: T.Validator<Props>
): T.ObjectValidator<
  import('@tldraw/utils').Expand<
    {
      [P in T.ExtractRequiredKeys<{
        id: TLAssetId
        meta: JsonObject
        props: Props
        type: Type
        typeName: 'asset'
      }>]: {
        id: TLAssetId
        meta: JsonObject
        props: Props
        type: Type
        typeName: 'asset'
      }[P]
    } & {
      [P_1 in T.ExtractOptionalKeys<{
        id: TLAssetId
        meta: JsonObject
        props: Props
        type: Type
        typeName: 'asset'
      }>]?:
        | {
            id: TLAssetId
            meta: JsonObject
            props: Props
            type: Type
            typeName: 'asset'
          }[P_1]
        | undefined
    }
  >
>

Parameters

NameDescription

type

Type

The type of the asset

props

T.Validator<Props>

The validator for the asset's props

Returns

T.ObjectValidator<
  import('@tldraw/utils').Expand<
    {
      [P in T.ExtractRequiredKeys<{
        id: TLAssetId
        meta: JsonObject
        props: Props
        type: Type
        typeName: 'asset'
      }>]: {
        id: TLAssetId
        meta: JsonObject
        props: Props
        type: Type
        typeName: 'asset'
      }[P]
    } & {
      [P_1 in T.ExtractOptionalKeys<{
        id: TLAssetId
        meta: JsonObject
        props: Props
        type: Type
        typeName: 'asset'
      }>]?:
        | {
            id: TLAssetId
            meta: JsonObject
            props: Props
            type: Type
            typeName: 'asset'
          }[P_1]
        | undefined
    }
  >
>
Prev
useUiEvents
Next
createBindingId