Typescript models do not have relationship functions
Author: thirionloganCreated Aug 16, 2021Updated Aug 10, 2023
Introduction
When I make a simple belongsTo relationship on a model, I get an error that states Property 'belongsTo' does not exist on type 'Object | typeof Model'.
Steps to reproduce issue
Example:
export const Page = bookshelf.model('Page', {
tableName: 'page',
book() {
return this.belongsTo(Book);
},
});Expected behaviour
I expect to be able to use belongsTo without typescript errors
Actual behaviour
When defining a model in a typescript file, belongsTo gets a ts(2339) error: Property 'belongsTo' does not exist on type 'Object | typeof Model'.
Source: bookshelf/bookshelf