1

There is a type that needs to be created in order to have custom strings inside. Something like:

type Names = { customName: "name1" | "name2" }

Since, what is planned is to have the "nameX" called from .env variables, I'd like to be able to do something like this:

type Names = {customName: process.env.name1 |  process.env.name2 }

Instead, as a result, the process. is not recognized Cannot find namespace 'process'.

1 Answer 1

3

process.env is an Object, not a type!

I think what you're trying to say is

type Names = {
    customName: typeof process.env.name1 | typeof process.env.name2
}

However, the type definition of process.env is

interface ProcessEnv extends Dict<string> {
    TZ?: string;
}

So if you want to achieve your purpose, you need to redefine process.env like this

declare global {
    namespace NodeJS {
        interface ProcessEnv {
            name1?: string
            name2?: string
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.