Skip to content

Feature: support narrowing Mixed to a union of concrete types. #6

@Raynos

Description

@Raynos

We currently support narrowing a union to a smaller union, or an object to a more strict object.

We do not yet support narrowing a mixed data type to a union of concrete types, for example a function gaurd should produce a function type or a truthy gaurd should produce a union of "never falsey" values (aka everything except null/undefined...).

This would allow code to use type gaurds and produce concrete types from mixed types.

/* getObjectField: (obj: Mixed, key: String) => Object | null*/
function getObjectField(obj, key) {
    if (obj && typeof obj === 'object' &&
        obj[key] && typeof obj[key] === 'object'
    ) {
        return obj[key];
    }

    return null;
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions