0.2.0-beta.891 • Published 2 years ago
@yavin/model-types v0.2.0-beta.891
@yavin/model-types
Contains the TypeScript definitions for the following json:api objects stored in the webservice package
Dashboard
, DashboardWidget
, Report
, DeliveryRule
, User
, Role
Examples
You'll need to cast your responses using the JSONAPI<RequestedObject, IncludedType>
type with the models you are requesting
import type { Dashboard, DashboardWidget, JSONAPI } from '@yavin/model-types';
const response = await fetch('yavin.webservice/api/v1/dashboards/12?include=widgets');
const jsonApi = (await response.json()) as JSONAPI<Dashboard, DashboardWidget>;
//now typed
jsonApi.data.attributes.presentation.layout[0].widgetId;
jsonApi.included[0].type === 'dashboardWidgets';
jsonApi.included[0].attributes.requests[0];
Here are more examples of fetching resources and how to type the response
fetch('*') | Response Type |
---|---|
/reports | JSONAPI<Report[]> |
/report/12 | JSONAPI\ |
/report/12?include=owner | JSONAPI<Report, User> |
/dashboards/13?include=widgets | JSONAPI<Dashboard, DashboardWidget> |
/deliveryRules/3?include=deliveredItem | JSONAPI<DeliveryRule, Report | Dashboard> |
0.2.0-beta.902
2 years ago
0.2.0-beta.901
3 years ago
0.2.0-beta.900
3 years ago
0.2.0-beta.899
3 years ago
0.2.0-beta.897
3 years ago
0.2.0-beta.896
3 years ago
0.2.0-beta.895
3 years ago
0.2.0-beta.894
3 years ago
0.2.0-beta.893
3 years ago
0.2.0-beta.892
3 years ago
0.2.0-beta.891
3 years ago