The Scrivito SDK includes type definitions for the building blocks of Scrivito-related entities such as CMS objects and widgets.
The Scrivito SDK includes type definitions for the building blocks of Scrivito-related entities such as CMS objects and widgets.
If you are new to TypeScript, you might first want to check out typescriptlang.org or the many other resources on the web (e.g., What is TypeScript and why would I use it in place of JavaScript?) before diving straight in here.
To try out the Scrivito SDK’s TypeScript beta, just install the latest version of the SDK:
As an example, here’s how the “BlogOverviewWidget” class from the Scrivito Example Application would look like in TypeScript:
The only required change is the new filename extension.
And here’s how the “BlogOverviewWidget” component from the Scrivito Example Application would look like in TypeScript:
As you can see, the BlogOverviewWidget
argument informs TypeScript that the widget
prop is a Scrivito.Widget
, and hence, get
can be called on it.
[New in 1.27.0]It also informs TypeScript about the type of the values get
returns from the widget
. For example, the result of widget.get("tags")
is automatically assumed to be of the string[]
type since tags
is defined as stringlist
. Analogously, widget.get("maxItems")
is assumed to return a number | null
.