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

Additional Properties - typing is too loose for typescript #512

Open
zcstarr opened this issue Dec 29, 2021 · 0 comments
Open

Additional Properties - typing is too loose for typescript #512

zcstarr opened this issue Dec 29, 2021 · 0 comments

Comments

@zcstarr
Copy link

zcstarr commented Dec 29, 2021

Additional properties and Patterned Properties append an any type to the end of the typing. The JSON schema spec doesn't quite line up with the typings generated. This would be a potentially breaking change for consuming clients. As they would all of a sudden generate types that didn't work with any. We want to move slowly here about introducing more specificity.

image

suggested change is probably

    if (s.additionalProperties ===  true || s.additionalProperties === undefined) {
      propertyTypings.push("  [k: string]: any;");
      }
    else if (s.additionalProperties !== false) {
      const subTypes: string[] = [];
      Object.values(s.additionalProperties!).forEach((prop: JSONSchema) => {
        const title = this.getSafeTitle(this.refToTitle(prop));
        if (subTypes.includes(title) === false) {
          subTypes.push(title);
        }
      });
      propertyTypings.push(`  [k: string]: ${subTypes.join(" | ")}`);
    } 

This issue will serve as tracking for open-rpc changes floating down the pipeline.

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

1 participant