Skip to content

Require top-level config values while allowing to override config file #1287

@jescalada

Description

@jescalada

Currently, top-level config values are not required, which means that the generated config types are optional. This forces us to use fallbacks, check if values are present or cast them:

app.use(
  session({
    store: db.getSessionStore(),
    secret: config.getCookieSecret() as string,
    resave: false,
    saveUninitialized: false,
    cookie: {
      secure: 'auto',
      httpOnly: true,
      maxAge: (config.getSessionMaxAgeHours() || DEFAULT_SESSION_MAX_AGE_HOURS) * 60 * 60 * 1000,
    },
  }),
);

Describe the solution you'd like
Adding the parameters to the "required" list will break tests that override the config entirely since it errors out if the entries aren't present. The best solution seems to be to post-process the generated config types so that the top-level properties are wrapped in Required types. This allows stronger typing as well as overriding.

We should also consider how we can set default values for the config - see the related discussion: #1202 (comment)

Additional context
#1202 (comment)
#1202 (comment)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions