Meteor.settings and typescript

Hey everyone. I am trying to create types for my settings.json values.

I’ve been able to extend it (and add types to it as necessary), but I can’t seem to figure out how to modify the type for Meteor.settings.public. Meteor already provides a type for that of { [id: string]: any; }.

Any recommendations or patterns, generally speaking, for adding types to Meteor.settings, and specifically to override Meteor.settings.public?

Thanks!

In your tsconfig you can define some overrides
“typeRoots”:[“./types/overrides.ts”],

And then in types/overrides if you do this:

declare module "meteor/meteor" {
  namespace Meteor {
    interface Settings {
      settingValue: "blah";
    }
  }
}

Which allows you to override Meteor.settings

Sadly, the way it is currently defined I don’t think you can override Meteor.settings.public

1 Like

Since you don’t really have control over what gets sent into Meteor.settings (so easy to make mistakes eg when passing in from an env var) I would recommend a zod schema validation wrapping your access to Meteor.settings

2 Likes

This makes sense to me. I was planning to use zod to parse them ala Matt Pocock’s video here: https://www.youtube.com/watch?v=q1im-hMlKhM. So, in light of the fact that I can’t directly change the type of Meteor.settings.public, the wrapper seems like it should work.

Thanks!