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

koa-ts example doesn't work #2361

Open
rizen opened this issue Mar 5, 2023 · 2 comments
Open

koa-ts example doesn't work #2361

rizen opened this issue Mar 5, 2023 · 2 comments
Labels

Comments

@rizen
Copy link

rizen commented Mar 5, 2023

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.
@rizen
Copy link
Author

rizen commented Mar 5, 2023

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.

@lehni lehni added the docs label Apr 15, 2023
@hellokirk
Copy link

.insertGraph(ctx.request.body as Person)

or

.insertGraph(ctx.request.body as Movie)

as appropriate will fix those

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

No branches or pull requests

3 participants