Skip to content

NativeMethodsWithoutBody

Extracts request method keys whose body type is void or undefined. These methods can be called without a request body.

Importing

ts
import type { NativeMethodsWithoutBody } from '@almighty-shogun/webkit-native-bridge'

Usage

ts
import type { NativeMethodsWithoutBody } from '@almighty-shogun/webkit-native-bridge'

type Requests = {
    getUser: { body: { id: string }; response: { name: string } }
    ping: { body: void; response: 'pong' }
}

type MethodsWithoutBody = NativeMethodsWithoutBody<Requests>;

// 'ping'

Parameters

NameDescription
TRequestsRequest map to inspect for methods that accept no body.

Returns

A TypeScript type for native bridge APIs. It is erased at runtime and is used only by TypeScript to describe the shape of values passed to or returned from the package APIs.

Type signature

ts
type NativeMethodsWithoutBody<
    TRequests extends NativeBridgeRequestMap
> = {
    [TMethod in keyof TRequests]:
        [NativeRequestBody<TRequests, TMethod>] extends [void]
        ? TMethod
        : [NativeRequestBody<TRequests, TMethod>] extends [undefined]
            ? TMethod
            : never;
}[keyof TRequests];

All packages are released under the MIT License.