wrap-cli icon indicating copy to clipboard operation
wrap-cli copied to clipboard

TypeScript App/Plugin Codegen Types Aren't Very Type-Safe

Open dOrgJelli opened this issue 3 years ago • 0 comments

Currently, most-all interface types for TypeScript applications are like so:

interface ModuleMethodInput extends Record<string, unknown> {
  argument?: Types.String | null;
}

export const Module = {
  method: async (
    input: ModuleMethodInput,
    client: Client
  ): Promise<InvokeApiResult<...>> => {
    ...
  }
}

The problem is that our input types extend from Record<string, unknown>, which is a generic property-map. This means that code like this will still compile, when it shouldn't:

Module.method({ foo: "value" });
// ^ "foo" should be "argument"

dOrgJelli avatar Jun 03 '22 02:06 dOrgJelli