jsontypedef / json-typedef-codegen

A CLI tool that generates code from JSON Typedef schemas
https://jsontypedef.com/docs/tools/jtd-codegen
MIT License
154 stars 31 forks source link

TypeScript: `any` vs `unknown` #76

Open TomokiMiyauci opened 1 year ago

TomokiMiyauci commented 1 year ago

Currently, empty forms are generated as any type.

In TypeScript, there are few situations where the any type is more suitable than the unknown type.

Both are tolerant of assignments. unknown is more type-safe than any because it is strictly for reference.

I think the unknown type is better suited for the role of a code generator.

joshgillies commented 1 year ago

As a work around to the above, you could do something like the following to explicitly output an unknown type:

{
  "data": {
    "metadata": {
      "typescriptType": "unknown"
    }
  }
}