Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with runtypes wiki outdated? #27

Open
vjocw opened this issue Sep 7, 2020 · 1 comment
Open

Usage with runtypes wiki outdated? #27

vjocw opened this issue Sep 7, 2020 · 1 comment

Comments

@vjocw
Copy link

vjocw commented Sep 7, 2020

Hello,

I'm looking to use rest.ts with runtypes and tried this example: https://github.com/hmil/rest.ts/wiki/Usage-with-Runtypes. But I'm getting errors in a few places:

const FlowerIndexedAttribute = rt.Union('color', 'name');

gives me:

Argument of type '"color"' is not assignable to parameter of type 'Runtype<unknown>'.ts(2345)

And when I try to use it within main-server.ts:

const router = buildRouter(flowerAPI, (_) => _
  .listFlowers(async () => {
    return [
      {
        name: '',
        color: '',
        id: ''
      }
    ]
  })
)

I get:

Argument of type '() => Promise<{ name: string; color: string; id: string; }[]>' is not assignable to parameter of type 'RouteHandler<Readonly<RemoveKey<RemoveKey<EmptyInitialEndpointDefinition<"GET">, "query"> & { query: { sortBy: Union2<Runtype<unknown>, Runtype<unknown>>; filterBy: Union2<...>; }; }, "response"> & { ...; }>>'.
  Type 'Promise<{ name: string; color: string; id: string; }[]>' is not assignable to type 'PromiseOrValue<{ tag: "array"; element: { tag: "record"; fields: { name: { tag: "string"; assert: (x: any) => asserts x is string; check: (x: any) => string; validate: (x: any) => Result<string>; guard: (x: any) => x is string; ... 6 more ...; _falseWitness: string; }; color: { ...; }; id: { ...; }; }; ... 14 more ....'.
    Type 'Promise<{ name: string; color: string; id: string; }[]>' is not assignable to type 'PromiseLike<{ tag: "array"; element: { tag: "record"; fields: { name: { tag: "string"; assert: (x: any) => asserts x is string; check: (x: any) => string; validate: (x: any) => Result<string>; guard: (x: any) => x is string; ... 6 more ...; _falseWitness: string; }; color: { ...; }; id: { ...; }; }; ... 14 more ...;...'.
      Types of property 'then' are incompatible.
        Type '<TResult1 = { name: string; color: string; id: string; }[], TResult2 = never>(onfulfilled?: (value: { name: string; color: string; id: string; }[]) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<...>) => Promise<...>' is not assignable to type '<TResult1 = { tag: "array"; element: { tag: "record"; fields: { name: { tag: "string"; assert: (x: any) => asserts x is string; check: (x: any) => string; validate: (x: any) => Result<string>; guard: (x: any) => x is string; ... 6 more ...; _falseWitness: string; }; color: { ...; }; id: { ...; }; }; ... 14 more ...;...'.
          Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
            Types of parameters 'value' and 'value' are incompatible.
              Type '{ name: string; color: string; id: string; }[]' is missing the following properties from type '{ tag: "array"; element: { tag: "record"; fields: { name: { tag: "string"; assert: (x: any) => asserts x is string; check: (x: any) => string; validate: (x: any) => Result<string>; guard: (x: any) => x is string; ... 6 more ...; _falseWitness: string; }; color: { ...; }; id: { ...; }; }; ... 14 more ...; _falseWitne...': tag, element, isReadonly, asReadonly, and 11 more.ts(2345)

@hmil
Copy link
Owner

hmil commented Sep 19, 2020

Hi @vincentjocodes, this is strange. Can you let me know which version of runtypes you are using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants