API reference › @evolu/common › Type › Typed
Defined in: packages/common/src/Type.ts:8882
A structurally tagged value created by typed.
Typed unions model mutually exclusive states as separate variants instead of
combinations of flags and optional properties. TypeScript narrows a union by
its literal type property. To enforce exhaustive handling, return from
every case of a value-producing switch or assert that the remaining value is
never in the default case of a side-effecting switch.
Example
import { type Typed } from "@evolu/common";
type Status = Typed<"Pending"> | Typed<"Completed">;
const getStatusMessage = (status: Status): string => {
switch (status.type) {
case "Pending":
return "Waiting";
case "Completed":
return "Done";
}
};
expect(getStatusMessage({ type: "Pending" })).toBe("Waiting");
Extended by
DecryptWithXChaCha20Poly1305ErrorFetchTransportErrorFetchStatusErrorFetchBodyErrorSomeNoneDoneSqlIdentifierRawSqlRunStateRunningRunStateAbortedRunStateSettledRunEventDataChildAddedRunEventDataChildRemovedRunEventDataStateChangedRetryErrorWebSocketSendErrorWebSocketConnectErrorWebSocketConnectionErrorWebSocketConnectionCloseErrorAppOwnerShardOwnerSharedOwnerSharedReadonlyOwnerOwnerWebSocketTransportProtocolHeaderProtocolVersionErrorProtocolInvalidDataErrorProtocolWriteKeyErrorProtocolWriteErrorProtocolQuotaErrorProtocolSyncErrorProtocolTimestampMismatchErrorApplyProtocolMessageAsClientResponseApplyProtocolMessageAsClientNoResponseApplyProtocolMessageAsClientBroadcastApplyProtocolMessageAsRelayResultStorageQuotaErrorTimestampDriftErrorTimestampCounterOverflowErrorTimestampTimeOutOfRangeErrorNodeSignalAbortReasonSpawnError
Properties
type
readonly type: Tag;
Defined in: packages/common/src/Type.ts:8883