#how to pass generic into module-definition file?

3 messages · Page 1 of 1 (latest)

karmic barn
#

Is there an alternative way to declare the module-definition for an abstract module such that i can pass a generic to my module options interface? In the example below I have no way of piping through the generic TSchema to provide typings for my drizzle database schema...

import { ConfigurableModuleBuilder } from "@nestjs/common";
import type { DrizzlePlanetScaleModuleOptions } from "./drizzle-planet-scale.types";

export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } =
  new ConfigurableModuleBuilder<DrizzlePlanetScaleModuleOptions<TSchema>>()
    .setClassMethodName("forRoot")
    .setExtras(
      {
        isGlobal: true,
      },
      (definition, extras) => ({
        ...definition,
        global: extras.isGlobal,
      }),
    )
    .build();
rugged gyro
#

What's the reason you need to pass the generic to the module?

karmic barn
#

@rugged gyro the TSchema type ultimately defaults to Record<string, never> when a generic isn't provided which ends up stuffing up my typesafety. i ultimately decided to just do it the ol fashioned way and implement my own forRoot/forRootAsync static methods but in retrospect i was prolly being abit overzealous as it not long dawned on me i have to define the schema when importing it into a consuming module anyway, not too reminiscent of ConfigService<T> typesafety...