Typescript question

I have code like this but I think my types are wrong because I cant access shape of zod schema on my class, also on comments I have some questions, any idea? I would like to be able to get schema on my database class correctly:
import z, { type Schema } from "zod";

export class Database<T> {
  public schema;
  constructor({ schema }: { schema: Schema<T> }) {
    this.schema = schema;
    //here i cant this.schema.shape.user;
    //console.log(this.schema.shape.user)

    //how to access user object from schema
    //this.schema.user
  }

  async create() {}
}


import { it } from "vitest";
import { z } from "zod";
import { Database } from "./index";

const userSchema = z.object({
  user: z.object({ id: z.number(), name: z.string() }),
});

//here i can userSchema.shape.user;

export type UserSchema = z.infer<typeof userSchema>;

it("Should create a database instance with correct schema", async () => {
  const database = new Database<UserSchema>({ schema: userSchema });
  //what should i do to be able to do database.user.create()
});
Was this page helpful?