Debian Codegraph @

types/tests/model-test.ts

raw
1 import { Model, Registry } from "miragejs";
2 import Schema from "miragejs/orm/schema";
3
4 const PersonModel = Model.extend({
5 name: "hello",
6 });
7
8 declare const schema: Schema<Registry<{ person: typeof PersonModel }, {}>>;
9
10 const people = schema.all("person");
11
12 people.length; // $ExpectType number
13 people.modelName; // $ExpectType string
14 people.models.map((model) => {
15 model.id; // $ExpectType string | undefined
16 model.name; // $ExpectType string
17 model.modelName; // $ExpectType string
18 model.attrs; // $ExpectType { name: string; }
19 model.foo; // $ExpectError
20
21 model.save(); // $ExpectType void
22 model.reload(); // $ExpectType void
23 model.destroy(); // $ExpectType void
24
25 model.update("name", "goodbye"); // $ExpectType void
26 model.update("name", false); // $ExpectError
27 model.update("bad", "ok"); // $ExpectError
28 });
29
30 schema.create("person").name; // $ExpectType string
31 schema.create("person", {}).name; // $ExpectType string
32 schema.create("person", { name: "custom" }).name; // $ExpectType string
33
34 schema.create("person", { name: 123 }); // $ExpectError
35 schema.create("person", { foo: "bar" }); // $ExpectError