Generate types
Get type-safe access to environment variables with varlock codegen
Use this pattern to generate a TypeScript declaration file from your schema, so
process.env access is fully typed.
Update the schema
Add the @generateTsTypes decorator to your .env.schema header:
# @generateTsTypes(path=types/env.d.ts)The path is relative to the schema file. Varlock writes the declaration file
to that location.
Add a script
Add a generate:env script to your package.json:
{
"scripts": {
"generate:env": "varlock codegen"
}
}Run it to generate (or regenerate) the types:
npm run generate:envThe generated file augments process.env with the variables defined in your
schema. Commit it to the repository so editors pick up the types without running
the generator.