Skip to content

expand() context types do not allow undefined values even though the code implementation does #79

@msheakoski

Description

@msheakoski

I noticed when updating to v3 and using the package's internal types, undefined values passed to expand() result in an error. The current types do not reflect the actual behavior of the JavaScript code, which accepts null and undefined and converts it to an empty string (see test below). Updating the PrimitiveValue type to include undefined would fix this issue:

// proposed fix
export type PrimitiveValue = string | number | boolean | null | undefined;

export type PrimitiveValue = string | number | boolean | null;
export interface Template {
expand(context: Record<string, PrimitiveValue | PrimitiveValue[] | Record<string, PrimitiveValue | PrimitiveValue[]>>): string;
}

test('expand variables that are undefined or null', () => {
assert('{undef}', '');
assert('{null}', '');
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions