Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Allow defining an endpoint without a server-side runtime parsing #2

Open
Schniz opened this issue Jun 30, 2022 · 1 comment
Open

Allow defining an endpoint without a server-side runtime parsing #2

Schniz opened this issue Jun 30, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@Schniz
Copy link
Collaborator

Schniz commented Jun 30, 2022

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 }) => {
 ...
}));
@Schniz Schniz added the enhancement New feature or request label Jun 30, 2022
@Schniz Schniz changed the title Allow using query(...) without a server-side runtime parsing Allow defining an endpoint without a server-side runtime parsing Jun 30, 2022
@jguddas
Copy link

jguddas commented Jul 8, 2022

+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 }) => {
  ...
}));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants