Extend
Create a TypeScript Client Wrapper
Build and ship your own TypeScript client wrapper using the types and client from @ts-kizuna/fetch.
@ts-kizuna/fetch exports new KizunaClient() and the full routes type system. You can wrap these to build hooks, an SDK layer, or any other integration, with no generator needed.
New first-party client PRs will be declined, because we can't maintain what we don't know well. The client API is public so you can build your own.
Pattern
import { KizunaClient, type Client } from '@ts-kizuna/fetch';
import { contract } from '@shared/contract';
const baseClient = new KizunaClient(contract, {
baseUrl: 'http://localhost:3000',
});
export function createMyClient() {
return {
getUser: (id: string) =>
baseClient.users.getUser({
params: {
id,
},
}),
createUser: (data: Parameters<typeof baseClient.users.createUser>[0]['body']) =>
baseClient.users.createUser({
body: data,
}),
};
}Types
The key types from @ts-kizuna/fetch:
| Type | Description |
|---|---|
Client<T> | The full typed client shape for your routes |
These are fully generic, so pass typeof routes or typeof routes.someRoute to get typed arguments and responses for your wrapper.
Publishing
ts-kizuna does not maintain third-party client libraries. Build yours and publish it as its own package.