NativeErrorCode
Extracts the native error code union for a method from a request map. If the method does not define an errorCode, the type falls back to string.
Importing
ts
import type { NativeErrorCode } from '@almighty-shogun/webkit-native-bridge'Usage
ts
import type { NativeErrorCode } from '@almighty-shogun/webkit-native-bridge'
type Requests = {
getUser: {
body: { id: string }
response: { name: string }
errorCode: 'USER_NOT_FOUND'
}
}
type GetUserCode = NativeErrorCode<Requests, 'getUser'>;
// 'USER_NOT_FOUND'Parameters
| Name | Description |
|---|---|
TRequests | Request map containing the method definition. |
TMethod | Method key whose native error code should be resolved. |
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 NativeErrorCode<
TRequests extends NativeBridgeRequestMap,
TMethod extends keyof TRequests
> =
TRequests[TMethod] extends {
errorCode?: infer TErrorCode extends string
}
? TErrorCode
: string;