glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
11.77k stars 1.04k forks source link

feat: Add const typing for Language Names #2554

Closed inferrinizzard closed 1 month ago

inferrinizzard commented 3 months ago

Description

Moves displayName, names, extension to external consts in each TargetLanguage file, and then passed as a generic arg to the base TargetLanguage class. This allows them to be statically analysed by the TypeScript compiler - leading to stricter typings for languages.

*this is a minor breaking change for anyone who was inheriting from an existing TargetLanguage class, guide on how to properly extend custom classes to come

Motivation and Context

Previously, the lang option would allow for string | TargetLanguage - which would allow for any arbitrary string to be passed and would cause errors at runtime instead of at write time. This change shifts that error left and prevents any incorrect strings from being passed in the first place.

Previous Behaviour / Output

options.lang used to be: image

New Behaviour / Output

now looks like: image

How Has This Been Tested?

Screenshots (if appropriate):