Skip to content

Usage with runtypes wiki outdated? #27

Description

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions