vuex-orm

"TypeError: this.types is not a function" when using "vuex-orm-decorators"


I'm trying to use the npm package 'vuex-orm-decorators' from https://github.com/scotley/vuex-orm-decorators#readme

When I try to insert into the DB, I get the error TypeError: this.types is not a function

Entity looks like this

import { Model } from "@vuex-orm/core";
import { NumberField, OrmModel, StringField } from "vuex-orm-decorators";

@OrmModel("races")
export default class Race extends Model {
  @NumberField()
  public ID!: number;

  @StringField()
  public Name!: string;
}

store looks like this:

import Vue from "vue";
import Vuex from "vuex";
import { ORMDatabase } from "vuex-orm-decorators";

Vue.use(Vuex);

export default new Vuex.Store({
  .
  .
  .
  plugins: [ORMDatabase.install()]
});

Also, maybe this is a clue.... in Vuex-Orm, this.setters is returning a value, but this.setters('all') is returning undefined.

/**
 * Get all records.
 */
Model.all = function () {
   return this.getters('all')();
};

From seeing the undefined basic fields and functions, it seems like the vuex-orm database isn't getting set up correctly. Any ideas?

I tried to create a stackoverflow tag for vuex-orm-decorators, but I'm not quite at 1500 rep yet, so I just tagged it as vuex-orm.


Solution

  • There is a small bug in vuex-orm-decorators package in the implementation of the types function defined in Vuex-ORM Single Table Inheritance docs.

    I've created a fork in which I fixed this simple problem and created a pull request to update the original package.

    Lastly, I've to point that from my tiny dive into this package that it isn't fully ready yet for table inheritance features built in Vuex-ORM but still is great for simple use cases.