TypeScript
Type-safety patterns and inference in the Rising Tide SDK.
The Rising Tide SDK is written in strict TypeScript. All public APIs are fully typed.
Importing types
All protocol types are exported from the root @rising-tide/sdk entry point:
import type {
SmartProduct,
ProductInstance,
Contribution,
ContributionRole,
ProductStatus,
ProductDomain,
FundingGroup,
Invite,
} from "@rising-tide/sdk";The revenue-routing row type is Contribution (with ContributionRole for the role enum); there is no ProductContribution export.
Import from the SDK rather than defining your own local types. This keeps your app in sync with the protocol as types evolve.
Discriminated unions
SmartProduct is a union on domain. Each variant carries its own optional detail field, and the detail fields of the other domains are typed never:
type SmartProduct =
| SmartProductPage // domain: "PAGE", pageDetails?
| SmartProductEvent // domain: "EVENT", eventDetails?
| SmartProductPrediction // domain: "PREDICTION", bracketDetails?
| SmartProductGame; // domain: "GAME", gameLobbyDetails?Use a switch on domain to narrow the type:
function renderDetail(product: SmartProduct) {
switch (product.domain) {
case "PAGE":
return <PageView details={product.pageDetails} />;
case "EVENT":
return <EventView details={product.eventDetails} />;
case "PREDICTION":
return <BracketView details={product.bracketDetails} />;
case "GAME":
return <LobbyView details={product.gameLobbyDetails} />;
}
}The narrowing functions isPage, isEvent, isPrediction and isGame do the same as a type guard. The detail field is present only when the read asked for it with include (see rtClient.smartProducts).
Strict mode
The SDK is compiled with strict: true. Client apps should also use strict mode. The SDK exports will not type-check cleanly with strict: false.
Schema validation
The @rising-tide/sdk/schemas entry exports Zod schemas that mirror the SDK types. Use these for runtime validation of API responses in tests:
import { SmartProductSchema } from "@rising-tide/sdk/schemas";
const result = SmartProductSchema.safeParse(apiResponse);