Type Alias IPropagation<StatusMap, Success>

IPropagation:
    | {
        [P in keyof StatusMap]: IBranch<
            P extends Success ? true : false,
            P,
            StatusMap[P],
        >
    }[keyof StatusMap]
    | IBranch<false, unknown, unknown>

Propagation type.

IPropagation is a type gathering all possible status codes and their body data types as a discriminated union type. You can specify the status code and its body data type just by using conditional statement like below.

type Output = IPropagation<{
200: ISeller.IAuthorized;
400: TypeGuardError.IProps;
>};

const output: Output = await sdk.sellers.authenticate.join(input);
if (output.success) {
// automatically casted to "ISeller.IAuthorized" type
const authorized: ISeller.IAuthorized = output.data;
} else if (output.status === 400) {
// automatically casted to "TypeGuardError.IProps" type
const error: TypeGuardError.IProps = output.data;
} else {
// unknown type when out of pre-defined status codes
const result: unknown = output.data;
}

For reference, this IPropagation type is utilized by SDK library generated by @nestia/sdk, when you've configured INestiaConfig.propagate to be true. In that case, SDK functions generated by @nestia/sdk no more returns response DTO typed data directly, but returns this IPropagation typed object instead.

Type Parameters

  • StatusMap extends { [P in Status]?: any }

    Map of status code and its body data type.

  • Success extends number = 200 | 201

    Default success status code.

Jeongho Nam - https://github.com/samchon