DEV Community

Discussion on: Using a TypeScript interface to define model properties in Objection.js

Collapse
htunnicliff profile image
Hunter Tunnicliff
import { Model, ModelObject } from "objection";

export default class Movie extends Model {
  static tableName = "movies";

  id!: number;
  title!: string;
  release_date!: Date;
}

// The `ModelObject` generic gives you a clean interface
// that can be used on the frontend, without any of the
// objection Model class properties or methods.
type MovieShape = ModelObject<Movie>;
Enter fullscreen mode Exit fullscreen mode
Collapse
tylerlwsmith profile image
Tyler Smith Author

Dang, I had no idea! This is way better. Thank you for sharing, Hunter.

Collapse
41y08h profile image
Piyush

you can set "strictPropertyInitialization": false, in you tsconfig and don't have to use !