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

Allow undefined env var values #615

Merged
merged 1 commit into from
Jan 27, 2020
Merged

Commits on Jan 27, 2020

  1. Allow undefined env var values

    While it doesn't make any sense, the typings for `process.env` is:
    
    ```ts
        interface ProcessEnv {
            [key: string]: string | undefined;
        }
    ```
    
    So assigning `process.env` to `IExecSyncOptions.env` in typescript with all typings turned on produces compiler errors (at least when strict null checking is applied).
    
    Without this simple typings adjustment, the following workaround in user code is required:
    
    ```ts
    function GetFilteredEnv() {
        const result = {};
        const block = process.env;
        for (const key in block) {
            if (block.hasOwnProperty(key)) {
                const value = block[key];
                if (value !== undefined) {
                    result[key] = value;
                }
            }
        }
        return result;
    }
    
    let options: IExecSyncOptions = { env: GetFilteredEnv() };
    ```
    
    But with this change it's as simple as:
    
    ```ts
    let options: IExecSyncOptions = { env: process.env };
    ```
    
    Which ironically is already what is done *within* this repo, but isn't a problem because the node typings aren't imported so `process.env` is typed as `any`.
    AArnott committed Jan 27, 2020
    Configuration menu
    Copy the full SHA
    b67d5a3 View commit details
    Browse the repository at this point in the history