Pular para o conteúdo principal

externalEntry <D>

Represents an Entry entity returned by the API.

An Entry’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 entities using a type definition file on your project. For instance:

// starlight.d.ts file
import { VisualField, MediaField } from '@starlightcms/js-sdk'

type PostFields = {
featured_image: MediaField
content: VisualField
}

declare module '@starlightcms/js-sdk' {
export interface DefaultModelDefinition {
posts: PostFields
}
}

You can place this type definition file anywhere in your repository, but it’s good practice to place it at the same level as your root index.ts file. Then, in your files, all SDK calls will correctly type posts:

import Starlight from '@starlightcms/js-sdk'

// response type will be StarlightItemResponse<Entry<PostFields>> on request success
const response = await Starlight.posts.entries.get('hello-world')

// helloWorld type is Entry<PostFields>
const helloWorld = response.data

See DefaultModelDefinition for more info.

Hierarchy

  • Omit<StarlightEntity, created_at>
    • Entry

Index

Properties

externalauthor

author: Author

externalcategory

category: null | ModelCategory

externaldata

data: D

externalid

id: number

externaloptionalmodel

model?: Model

externalpublished_at

published_at: null | string

externalslug

slug: string

externaltitle

title: string

externaloptionalupdated_at

updated_at?: string