amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.87k stars 543 forks source link

typescript/es6-declarations outputs wide types for string/number values #904

Closed iybaron closed 1 year ago

iybaron commented 1 year ago

Problem: Currently, the typescript/es6-declarations format assigns string tokens the type string, and number tokens the type number. As a result, tokens are un-assignable to stricter types, such as string literal unions, without type assertion. The assignment of type string to tokens with string values does not align with Typescript's built-in type inference, which assigns string-literal types to string variables.

Proposed Solution: Add feature flag options.outputLiteralTypes to the typescript/es6-declarations format's interface. If this boolean option is set to true, tokens with string or number values will be assigned literal types in the outputted files.

PR: https://github.com/amzn/style-dictionary/pull/857