@@ -12,15 +12,15 @@ This library aims to allow you to define environment variables in a more type-sa
12
12
example:
13
13
14
14
``` ts
15
- const environment = process .env .ENVIRONMENT ;
15
+ const environment = process .env .ENVIRONMENT
16
16
17
17
const makePayment = (amount : bigint ) => {
18
18
if (environment === ' prod' ) {
19
- makeRealPayment (amount );
19
+ makeRealPayment (amount )
20
20
} else {
21
- makeMockPayment (amount );
21
+ makeMockPayment (amount )
22
22
}
23
- };
23
+ }
24
24
```
25
25
26
26
What if you configured your server with ` ENVIRONMENT=production ` instead of ` ENVIRONMENT=prod ` ?
@@ -31,30 +31,30 @@ If you'd used TypedEnv instead, you'd get this
31
31
32
32
``` ts
33
33
const env = TypedEnv ({
34
- ENVIRONMENT: EnumVar ({options: [' dev' , ' staging' , ' production' ]}),
35
- });
34
+ ENVIRONMENT: EnumVar ({ options: [' dev' , ' staging' , ' production' ] }),
35
+ })
36
36
37
37
const makePayment = (amount : bigint ) => {
38
38
if (env .ENVIRONMENT === ' prod' ) {
39
39
// TypeError!
40
40
// `This condition will always return 'false' since
41
41
// the types '"dev" | "staging" | "production"' and
42
42
// '"prod"' have no overlap.`
43
- return makeRealPayment (amount );
43
+ return makeRealPayment (amount )
44
44
} else {
45
- return makeFakePayment (amount );
45
+ return makeFakePayment (amount )
46
46
}
47
- };
47
+ }
48
48
```
49
49
50
50
## What types are supported?
51
51
52
- Currently, strings, integers, and enums are supported, although you can define your own custom type
52
+ Currently, strings, enums, integers, and dates are supported, although you can define your own custom type
53
53
using the ` Declaration<T> ` type
54
54
55
55
``` ts
56
56
export type Declaration <T > = {
57
- variable? : string ; // The name of the environment variable; defaults to match the key if not specified
58
- parser: Parser <T >; // A function (value: string) => T
59
- };
57
+ variable? : string // The name of the environment variable; defaults to match the key if not specified
58
+ parser: Parser <T > // A function (value: string) => T
59
+ }
60
60
` ` `
0 commit comments