This is a great QoL addition that I've been using a lot from ts-dotenv, but the implementation details of this library is so different that another approach is better.
In ts-dotenv you specify an array that are cast as const as so:
LOG_LEVEL: {
type: [
'fatal' as const,
'error' as const,
'warn' as const,
'info' as const,
'debug' as const,
'trace' as const
],
default: 'info'
},
which gives you the type
'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace'
It would be amazing if we could conditionally do this for choices. Here is an example of how it can be done:
function stringLiteralArray<T extends string>(a: T[]) {
return a;
}
const fruits = stringLiteralArray(["Apple", "Orange", "Pear"]);
type Fruits = typeof fruits[number]
This is a great QoL addition that I've been using a lot from ts-dotenv, but the implementation details of this library is so different that another approach is better.
In ts-dotenv you specify an array that are cast as const as so:
which gives you the type
It would be amazing if we could conditionally do this for choices. Here is an example of how it can be done: