next-fetch
next-fetch copied to clipboard
Allow defining an endpoint without a server-side runtime parsing
trafficstars
When I asked for feedback, one person told me he does not like the fact this library forces you to declare a type in advance using zod, alternative libraries, or pass any object with the function parse.
So their idea was:
export const useMyHook = query((value: { untrusted: string }) => {
return "Hello, world!"
});
I am not so sure about it because I think we should have good defaults and suggest better and safer code. Maybe we can do something like:
import { unsafe } from 'next-swr-endpoints';
export const useMyHook = query(unsafe, (value: { untrusted: string }) => {
...
}));
// or as a function, because then I think that we can declare it as `unsafe<T>(): T`
export const useMyHook = query(unsafe(), (value: { untrusted: string }) => {
...
}));
+1 for not adding this.
If people really want this, they can add their own unsafe validator like this:
const unsafe = <T,>() => ({ parse: (v: unknown) => v as T })
export const useMyHook = query(unsafe<{ untrusted: string }>(), (value) => {
...
}));
export const useMyHook = query(unsafe<any>(), (value: { untrusted: string }) => {
...
}));