Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Type Safety to __ENV Variables #42

Open
Nathan-Bernardo opened this issue Nov 8, 2023 · 2 comments
Open

Adding Type Safety to __ENV Variables #42

Nathan-Bernardo opened this issue Nov 8, 2023 · 2 comments

Comments

@Nathan-Bernardo
Copy link

Hi guys, I added Typescript into my k6 scripts and I'm finding it difficult to extend the __ENV type. There are some __ENV variables I defined to be a number, but Typescript will define the value as a string rather than a number due to this type definition

// global.d.ts
declare global {
    const __ENV: { [name: string]: string };
}

Is there a way for me to extend the __ENV type definition? One thing I tried was defining my own global.d.ts file with the following:

declare global {
    namespace __ENV {
        const VUS: number
    }
}

but that didn't work.

@ppcano
Copy link
Collaborator

ppcano commented Nov 9, 2023

Hi @Nathan-Bernardo,

I wonder why do you need to extend _ENV?

If you need the VUS value, you can get it from the test.options object (k6/execution).

@Nathan-Bernardo
Copy link
Author

Hi @ppcano,

VUS just happens to be an environment variable I specified for my CI/CD pipeline. I realized I could have used the flag —vus to specify the number of VUs, but there are other environment variables that I would like to specify and they would be of type number. I know I could use “parseInt” to parse the string to a number, but I want to see if there was an option to extend __ENV, unless it’s unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants