Skip to content

Commit

Permalink
fix(types): changed NodeJS.ProcessEnv type to Record in node-config-p…
Browse files Browse the repository at this point in the history
…rovider (#4319)

* fix(types): changed NodeJS.ProcessEnv type to Record in node-config-provider package

* chore: added comments explaining the changes
  • Loading branch information
froggydood committed Jan 25, 2023
1 parent 640f7f6 commit 872fe07
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/node-config-provider/src/configLoader.spec.ts
Expand Up @@ -25,7 +25,8 @@ describe("loadConfig", () => {
(fromSharedConfigFiles as jest.Mock).mockReturnValueOnce(mockFromSharedConfigFilesReturn);
const mockFromStatic = "mockFromStatic";
(fromStatic as jest.Mock).mockReturnValueOnce(mockFromStatic);
const envVarSelector = (env: NodeJS.ProcessEnv) => env["AWS_CONFIG_FOO"];
// Using Record<string, string | undefined> instead of NodeJS.ProcessEnv, in order to not get type errors in non node environments
const envVarSelector = (env: Record<string, string | undefined>) => env["AWS_CONFIG_FOO"];
const configKey = (profile: Profile) => profile["aws_config_foo"];
const defaultValue = "foo-value";
loadConfig(
Expand Down
4 changes: 3 additions & 1 deletion packages/node-config-provider/src/fromEnv.spec.ts
Expand Up @@ -5,7 +5,9 @@ import { fromEnv, GetterFromEnv } from "./fromEnv";
describe("fromEnv", () => {
describe("with env var getter", () => {
const envVarName = "ENV_VAR_NAME";
const envVarGetter: GetterFromEnv<string> = (env: NodeJS.ProcessEnv) => env[envVarName]!;

// Using Record<string, string | undefined> instead of NodeJS.ProcessEnv, in order to not get type errors in non node environments
const envVarGetter: GetterFromEnv<string> = (env: Record<string, string | undefined>) => env[envVarName]!;
const envVarValue = process.env[envVarName];
const mockEnvVarValue = "mockEnvVarValue";

Expand Down
3 changes: 2 additions & 1 deletion packages/node-config-provider/src/fromEnv.ts
@@ -1,7 +1,8 @@
import { CredentialsProviderError } from "@aws-sdk/property-provider";
import { Provider } from "@aws-sdk/types";

export type GetterFromEnv<T> = (env: NodeJS.ProcessEnv) => T | undefined;
// Using Record<string, string | undefined> instead of NodeJS.ProcessEnv, in order to not get type errors in non node environments
export type GetterFromEnv<T> = (env: Record<string, string | undefined>) => T | undefined;

/**
* Get config value given the environment variable name or getter from
Expand Down

0 comments on commit 872fe07

Please sign in to comment.