Ask HN: Elevation Something to Consider When Deciding Where to Live?
4 pointsby shiny3 comments
export const makeRequest = <Name extends keyof Endpoints>(
_name: Name,
method: Endpoints[Name]['method'],
path: Endpoints[Name]['path'],
props: {
data: Endpoints[Name]['clientSends'];
onSuccess: (json: Endpoints[Name]['serverResponds']) => void;
onError: (json: any) => void;
}
) => { // ...
Dropping all of these typing shenanigans and going back to Elixir/Phoenix is always half-tempting, but I will soldier on for now... export type Endpoints = {
createProduct: {
path: '/api/products.json';
method: 'POST';
clientSends: { name: string };
serverResponds: ProductJSON;
};
}
The client can do `makeRequest('createProduct', ...)` and the Express server can use `registerEndpoint('createProduct', ...)` which must adhere to the schema defined above.