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

Update identityManagers type signature for ServerConfig, DbClass #597

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ declare module "miragejs/server" {
testConfig?: (this: Server<MirageRegistry<Models, Factories>>) => void;

inflector?: object;
identityManagers?: IdentityManager;
identityManagers?: Partial<
Record<keyof Models | "application", typeof IdentityManager>
>;
models?: Models;
serializers?: any;
factories?: Factories;
Expand Down Expand Up @@ -414,7 +416,10 @@ declare module "miragejs/db" {
};

class DbClass {
constructor(initialData: [], identityManagers?: IdentityManager[]);
constructor(
initialData: [],
identityManagers?: Record<string, IdentityManager>,
);

createCollection(name: string, initialData?: any[]): void;
dump(): void;
Expand Down
9 changes: 9 additions & 0 deletions types/tests/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
hasMany,
Factory,
} from "miragejs";
import IdentityManager from 'miragejs/identity-manager';

export default function config(this: Server): void {
this.namespace = "foo";
Expand Down Expand Up @@ -85,11 +86,19 @@ new Server({
this.get("/movies");
this.post("/movies");
},

identityManagers: {
application: IdentityManager,
},
});

// In contrast to `new Server`, `createServer` is able to infer
// type info from the models and factories you pass it
createServer({
identityManagers: {
pet: IdentityManager,
},

models: {
pet: Model.extend({
owner: belongsTo("person"),
Expand Down