Loopback-next: Property 'getIdOf' is missing in type 'typeof ..' in loopback 4

Created on 20 Nov 2018  路  5Comments  路  Source: strongloop/loopback-next

I create a project with lb4 and add models then i make datasource with mysql and create repository it gives error Property 'getIdOf' is missing.

src/repositories/customer.repository.ts:7:3 - error TS2344: Type 'Customer' does not satisfy the constraint 'Entity'.
Property 'getId' is missing in type 'Customer'.

7 Customer,
~~~~

src/repositories/customer.repository.ts:13:11 - error TS2345: Argument of type 'typeof Customer' is not assignable to parameter of type 'typeof Entity & { prototype: Customer; }'.
Type 'typeof Customer' is not assignable to type 'typeof Entity'.
Property 'getIdOf' is missing in type 'typeof Customer'.

13 super(Customer, dataSource);
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: lb-tsc es2017 --outDir dist
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/parikshitsaini/.npm/_logs/2018-11-20T05_03_20_287Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] prestart: npm run build
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/parikshitsaini/.npm/_logs/2018-11-20T05_03_20_798Z-debug.log

-->

question

Most helpful comment

@Mohit-Purbia when using DefaultCrudRepository, your model classes should inherit from Entity.

A Model is a generic model class that does not necessarily has any unique identifier. Entity is a Model that has a unique id (a primary key).

All 5 comments

@Mohit-Purbia , do you have an id set for the Customer model?
For example, something like:

@property({
    type: 'number',
    id: true, <------ specify this property is an id property
  })
  id?: number;

@Mohit-Purbia , do you have an id set for the Customer model?
For example, something like:

@property({
    type: 'number',
    id: true, <------ specify this property is an id property
  })
  id?: number;

yes @dhmlau --this are the entities

import {Model, model, property} from '@loopback/repository';

@model()
export class Customer extends Model {
  @property({
    type: 'number',
    id: true,
  })
  id?: number;

  @property({
    type: 'string',
  })
  name?: string;

  @property({
    type: 'string',
  })
  email?: string;

  constructor(data?: Partial<Customer>) {
    super(data);
  }
}

@Mohit-Purbia when using DefaultCrudRepository, your model classes should inherit from Entity.

A Model is a generic model class that does not necessarily has any unique identifier. Entity is a Model that has a unique id (a primary key).

@bajtos A quick query here. There was a proposal to filter out such model classes from showing up as selection during lb4 repository command run (Refer this - https://github.com/strongloop/loopback-next/pull/1746 and this - https://github.com/strongloop/loopback-next/issues/1698)
Any update on when can we expect that ? Actually, if provided, it can greatly reduce such possibility of issues.

@Mohit-Purbia when using DefaultCrudRepository, your model classes should inherit from Entity.

A Model is a generic model class that does not necessarily has any unique identifier. Entity is a Model that has a unique id (a primary key).

Thanks,@bajtos its working now. I used Entity in place of model.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

milindsingh picture milindsingh  路  3Comments

ThePinger picture ThePinger  路  3Comments

rexliu0715 picture rexliu0715  路  3Comments

shadyanwar picture shadyanwar  路  3Comments

shahulhameedp picture shahulhameedp  路  3Comments