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:
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
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 thedata
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:
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
:See DefaultModelDefinition for more info.