Routes should implement this interface to use with fetch function
Properties can be a value, or a function that returns a value to access this
this
Example with LavaSearch /loadsearch endpoint
/loadsearch
export class LoadSearchEndpoint implements RestEndpoint { constructor(public readonly query: string, public readonly types: string) {} public readonly pluginRequired = { name: 'lavasearch-plugin', version: '^1.0.0' }; public readonly endpoint = '/loadsearch'; public readonly params = () => ({ query: this.query, types: this.types }); public readonly T = t<{ tracks?: Track[]; albums?: Playlist[]; artists?: Playlist[]; playlists?: Playlist[]; texts?: { text: string; plugin: Record<string, unknown>; }; plugin: Record<string, unknown>; }>; } Copy
export class LoadSearchEndpoint implements RestEndpoint { constructor(public readonly query: string, public readonly types: string) {} public readonly pluginRequired = { name: 'lavasearch-plugin', version: '^1.0.0' }; public readonly endpoint = '/loadsearch'; public readonly params = () => ({ query: this.query, types: this.types }); public readonly T = t<{ tracks?: Track[]; albums?: Playlist[]; artists?: Playlist[]; playlists?: Playlist[]; texts?: { text: string; plugin: Record<string, unknown>; }; plugin: Record<string, unknown>; }>; }
Readonly
Lavalink endpoint
HTTP request headers
This hack is to work around TypeScript types not existing at runtime. We can specify the return type here.
Internal
Utility for specifying types in generic interfaces, workaround for TypeScript types not existing at runtime
This function is never actually called, so the implementation can be simply:
T = (response: unknown) => response as LavalinkResponse; Copy
T = (response: unknown) => response as LavalinkResponse;
Or using the t utility function
t
import { t } from 'shoukaku';T = t<LavalinkResponse>; Copy
import { t } from 'shoukaku';T = t<LavalinkResponse>;
Routes should implement this interface to use with fetch function
Properties can be a value, or a function that returns a value to access
thisExample
Example with LavaSearch
/loadsearchendpoint