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

ModelRelations type seems to always resolve to the 'never' type #2370

Open
tony-oldport opened this issue Mar 24, 2023 · 1 comment
Open
Assignees
Labels

Comments

@tony-oldport
Copy link

tony-oldport commented Mar 24, 2023

I'm using objection.js 3.0.0 with TypeScript and am trying to utilize the ModelRelations type which the docs say exists to "extract the relation names of the model class". Small example below results in the compilation error on modelRelations: Type 'string' is not assignable to type 'never'. ts(2322)

import { Model, ModelRelations, RelationMappings } from 'objection'
import { UserModel } from './UserModel'

export class TestModel extends Model {
  static tableName = 'test'
  static relationMappings = (): RelationMappings => ({
    user: {
      relation: Model.BelongsToOneRelation,
      modelClass: UserModel,
      join: {
        from: 'test.userId',
        to: 'users.id'
      }
    }
  })
}

type TestModelRelations = ModelRelations<TestModel>

export function testModelClass (): void {
  const modelRelations: TestModelRelations = 'thisvaluedoesntmatter'
  console.log(modelRelations)
}
@lehni lehni added the typings label Apr 15, 2023
@lehni lehni self-assigned this Apr 15, 2023
@lehni
Copy link
Collaborator

lehni commented Apr 15, 2023

Related: #2380

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

2 participants