Pular para o conteúdo principal

externalSingleton <D>

Represents a Singleton entity returned by the API.

A Singleton’s data field can be further typed by passing an object-like structure as the D generic type. This is useful to provide type-safety to your application, since the data field is a generic JS object by default.

It’s recommended to use the Field types provided by this SDK to type your Singletons. For instance:

import { StringField, VisualField, MediaField } from '@starlightcms/js-sdk'

type HomeFields = {
site_title: StringField
hero_image: MediaField
hero_content: VisualField
}

// response type will be StarlightItemResponse<Singleton<HomeFields>> on request success
const response = Starlight.singletons.get<HomeFields>('home')

// home type is Singleton<HomeFields>
const home = response.data

You could also place all your Singleton field types in the same type definition file used to configure Entry fields, which makes it easier to import these types in other files on your project. See DefaultModelDefinition for more info.

Hierarchy

  • Omit<StarlightEntity, created_at>
    • Singleton

Index

Properties

externaldata

data: D

externalid

id: number

externalpublished_at

published_at: null | string

externalslug

slug: string

externaltitle

title: string

externaloptionalupdated_at

updated_at?: string