pkl-community / pkl-typescript

TypeScript language bindings for the Pkl programming language
https://www.npmjs.com/package/@pkl-community/pkl-typescript
Apache License 2.0
104 stars 1 forks source link

Propagate Pkl type literals to TypeScript type literals #12

Closed jasongwartz closed 8 months ago

jasongwartz commented 8 months ago

Pkl supports string type literals, ie x: "asdf", where the string value of x can only be "asdf". https://pkl-lang.org/main/current/language-reference/index.html#string-literal-types

TypeScript also supports type literals: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types

To get better type inference in TypeScript, when it can be inferred that the value can only be that of the type literal, pkl-gen-typescript should create a TypeScript type literal that matches the Pkl type literal.