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

Argument of type '{ name: string; role: string[]; }' is not assignable to parameter of type 'Partial<ModelInitializ #1090

Open
vaynevayne opened this issue Sep 12, 2023 · 1 comment

Comments

@vaynevayne
Copy link

import { createServer, Model } from "miragejs"

export function makeServer({ environment = "test" } = {}) {
  let server = createServer({
    environment,

    models: {
      user: Model,
    },

    seeds(server) {
      server.create("user", { name: "admin",role:['admin'] })
      server.create("user", { name: "Alice",role:[] })
    },

    routes() {
      this.namespace = "api"

      this.get("/users", (schema) => {
        return schema.users.all()
      })
    },
  })

  return server
}
image
@IanVS
Copy link
Collaborator

IanVS commented Sep 12, 2023

When defining your models, you should use Model.extend<User>(defaultUser), where User is the type for the resource, and defaultUser is an example that has all of the properties specified, so that TS inference works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants