Skip to content

Additional Properties - typing is too loose for typescript #512

@zcstarr

Description

@zcstarr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions