transpiler icon indicating copy to clipboard operation
transpiler copied to clipboard

Additional Properties - typing is too loose for typescript

Open zcstarr opened this issue 3 years ago • 0 comments

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.

zcstarr avatar Dec 29 '21 18:12 zcstarr