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

Add way to remove additionalProperties ([property: string]: any) #311

Open
DylanVann opened this issue Aug 29, 2023 · 2 comments
Open

Add way to remove additionalProperties ([property: string]: any) #311

DylanVann opened this issue Aug 29, 2023 · 2 comments

Comments

@DylanVann
Copy link

DylanVann commented Aug 29, 2023

Currently the generated types for TypeScript look like:

export interface MyEventProperties {
  email: string
  [property: string]: any;
}

This means that if a property doesn't exist, or is removed, in Protocols, then it will not be a compile error. I think some users (including myself) would prefer to know about excess/removed properties if possible.

I believe that this could be changed by making the JSON Schema include additionalProperties: false on most definitions. It seems the default for QuickType is to generate [property: string]: any; if it is not set to false.

I tried to use a "Common JSON Schema" set to:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "context": {},
    "traits": {},
    "properties": {
      "type": "object",
      "additionalProperties": false
    }
  }
}

It did not work though.

@henryowens
Copy link

henryowens commented Aug 2, 2024

I had the same issue, I didn't manage to prevent the interface allowing any property however I did create a wrapper interface to achieve this:

type MakeStrict<T> = {
  [K in keyof T as string extends K
    ? never
    : number extends K
      ? never
      : K]: T[K];
};

export interface MyEventProperties {
  email: string
  [property: string]: any;
}

type StrictMyEventProperties = MakeStrict<MyEventProperties>

@dturkington49
Copy link

This is also an issue for my team. Built in tracking plan support here would be very valuable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants