Vincit / objection.js

An SQL-friendly ORM for Node.js

Home Page:https://vincit.github.io/objection.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

koa-ts example doesn't work

rizen opened this issue · comments

I'm on an M2 Mac running the latest OS. The regular koa example works, but the typescript one throws a bunch of errors.

jtsmith@jts-MacBook-Pro koa-ts % npm start

> objection-example-koa-ts@3.0.0 start
> npm run migrate && rm -rf dist && tsc && node dist/app.js


> objection-example-koa-ts@3.0.0 migrate
> knex migrate:latest

Using environment: development
Already up to date
api.ts:21:22 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(this: QueryBuilder<...>, graph: PartialModelGraph<Person, Person & GraphParameters>, options?: InsertGraphOptions | undefined): QueryBuilder<...>', gave the following error.
    Argument of type 'unknown' is not assignable to parameter of type 'PartialModelGraph<Person, Person & GraphParameters>'.
  Overload 2 of 2, '(this: QueryBuilder<...>, graph: PartialModelGraph<Person, Person & GraphParameters>[], options?: InsertGraphOptions | undefined): QueryBuilder<...>', gave the following error.
    Argument of type 'unknown' is not assignable to parameter of type 'PartialModelGraph<Person, Person & GraphParameters>[]'.

21         .insertGraph(ctx.request.body)
                        ~~~~~~~~~~~~~~~~


api.ts:97:75 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'PartialModelObject<Person>'.

97     const numUpdated = await Person.query().findById(ctx.params.id).patch(ctx.request.body)
                                                                             ~~~~~~~~~~~~~~~~

api.ts:121:78 - error TS2769: No overload matches this call.
  Overload 1 of 3, '(insert: PartialModelObject<Person>): QueryBuilder<Person, Person>', gave the following error.
    Argument of type 'unknown' is not assignable to parameter of type 'PartialModelObject<Person>'.
  Overload 2 of 3, '(insert: PartialModelObject<Person>[]): QueryBuilder<Person, Person[]>', gave the following error.
    Argument of type 'unknown' is not assignable to parameter of type 'PartialModelObject<Person>[]'.

121     const child = await Person.relatedQuery('children').for(personId).insert(ctx.request.body)
                                                                                 ~~~~~~~~~~~~~~~~


api.ts:170:72 - error TS2769: No overload matches this call.
  Overload 1 of 3, '(insert: PartialModelObject<Animal>): QueryBuilder<Animal, Animal>', gave the following error.
    Argument of type 'unknown' is not assignable to parameter of type 'PartialModelObject<Animal>'.
  Overload 2 of 3, '(insert: PartialModelObject<Animal>[]): QueryBuilder<Animal, Animal[]>', gave the following error.
    Argument of type 'unknown' is not assignable to parameter of type 'PartialModelObject<Animal>[]'.

170     const pet = await Person.relatedQuery('pets').for(personId).insert(ctx.request.body)
                                                                           ~~~~~~~~~~~~~~~~


api.ts:202:46 - error TS2769: No overload matches this call.
  Overload 1 of 3, '(insert: PartialModelObject<Movie>): QueryBuilder<Movie, Movie>', gave the following error.
    Argument of type 'unknown' is not assignable to parameter of type 'PartialModelObject<Movie>'.
  Overload 2 of 3, '(insert: PartialModelObject<Movie>[]): QueryBuilder<Movie, Movie[]>', gave the following error.
    Argument of type 'unknown' is not assignable to parameter of type 'PartialModelObject<Movie>[]'.

202     const movie = await Movie.query().insert(ctx.request.body)
                                                 ~~~~~~~~~~~~~~~~



Found 5 errors.

Since I'm installing this just to learn about objection I'm afraid I can't offer any insights as to why it doesn't work. But the regular koa example worked by just following the instructions.

.insertGraph(ctx.request.body as Person)

or

.insertGraph(ctx.request.body as Movie)

as appropriate will fix those