Ok, so the problem is that the parameter isn't always the orm but can also be a bookshelf instance
2023-09-01 24442, 2023
kellnerd
(in models/area.js)
2023-09-01 24417, 2023
kellnerd
I guess I will rename the parameter to ormOrBookshelf in that case
2023-09-01 24449, 2023
monkey
I can't definitely find what the type of that first parameter ormOrBookshelf would be when called from the model instance versus when called from the test file
2023-09-01 24419, 2023
monkey
But if you remove that `|| orm` and try to run that test file you might find out :)
2023-09-01 24409, 2023
kellnerd
I'll give that a try :)
2023-09-01 24409, 2023
kellnerd
After changing the test's import to point to '../../lib/func/area' it fails (as expected)
2023-09-01 24418, 2023
kellnerd
The simplest fix would be to adapt the test and change the expected parameter of the source to be a bookshelf instance.
2023-09-01 24453, 2023
kellnerd
On the other hand, all similar functions expect an ORM instance and not a Bookshelf...
2023-09-01 24450, 2023
kellnerd
Unfortunate that the Area model has to pass a Bookshelf because it doesn't know about the ORM.
2023-09-01 24435, 2023
kellnerd
TS isn't well equipped to handle this kind of inline hacks to support both :/
2023-09-01 24446, 2023
monkey
Right, I guess that's the issue then, when used in one of the model's functions we only have access to the bookshelf object, not the whole ORM
2023-09-01 24441, 2023
monkey
Although…
2023-09-01 24419, 2023
monkey
Could you please try to call recursivelyGetAreaParentsWithNames with `bookshelf.bookshelf` here?
The above happens 1) if I only remove `|| orm` or 2) if I remove `|| orm` and do the call with `bookshelf.bookshelf`or 3) if I only do the call with `bookshelf.bookshelf`.
2023-09-01 24428, 2023
monkey
Harumpf
2023-09-01 24433, 2023
kellnerd
So we either have to keep the parameter as type ORM | Bookshelf or change all calls to pass bookshalf or knex directly.
2023-09-01 24439, 2023
kellnerd
*bookshelf
2023-09-01 24436, 2023
kellnerd
Currently I have `const queryResult = await ((orm as ORM).bookshelf || (orm as Bookshelf)).knex.raw(rawSql);` as a somewhat ugly solution to satisfy TS :P
2023-09-01 24418, 2023
monkey
A typed version of the current mess is still an improvement
2023-09-01 24437, 2023
kellnerd
I thought I could do `const knex = orm.bookshelf ? orm.bookshelf.knex : orm.knex;` to let TS infer the correct type of orm, but that doesn't work...
2023-09-01 24459, 2023
kellnerd
TS already complains about the condition
2023-09-01 24456, 2023
kellnerd
Ha, I got it: `const knex = ('bookshelf' in orm) ? orm.bookshelf.knex : orm.knex;` works
2023-09-01 24410, 2023
monkey
Ah great
2023-09-01 24414, 2023
kellnerd
I forgot about the correct syntax for this :)
2023-09-01 24403, 2023
kellnerd
> @param {string} areaId - The entity model name.
2023-09-01 24426, 2023
kellnerd
Hehe, I guess the description is wrong and this is is the MBID?