DEV Community

Discussion on: React Native: Generating TypeScript Types for Environment Variables

Collapse
 
aamnahakram profile image
Aamnah Akram

Neat! I was looking for Typescript autocomplete for .env as well :)

One minor adjustment to this would be replacing envProdLine.includes("#") with envProdLine.startsWith("#"). Comment lines start with # so it only makes sense to use startsWith(). Otherwise it'd break (say undefined ) for any values that have # in it.

if (envProdLine.includes("=")) {
  if (envProdLine.startsWith("#")) {
    filteredEnvProd.push(envProdLine.split("#")[1].trim())
  } else {
    filteredEnvProd.push(envProdLine.trim())
  }
}
Enter fullscreen mode Exit fullscreen mode