rest.ts icon indicating copy to clipboard operation
rest.ts copied to clipboard

Usage with runtypes wiki outdated?

Open vvvjo opened this issue 5 years ago • 1 comments

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)

vvvjo avatar Sep 07 '20 17:09 vvvjo

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

hmil avatar Sep 19 '20 13:09 hmil