Skip to content

Cannot iterate over union of types (used to be possible in Ts-2.3) #18203

Closed as not planned
@apr-xaml

Description

@apr-xaml

TypeScript Version: 2.5.2

Code

type TypeDescription<T> = {[prop in keyof T]: undefined };

function getAllProperties<T>(typeDesc: (T|TypeDescription<T>)): ReadonlyArray<keyof T>
{
    const props: Array<keyof T> = [];

    for (var iPropName in typeDesc)
    {
        props.push(iPropName);
    }

    return props;
}

Expected behavior:
Should compile file (used to be in Ts-2.3)

Actual behavior:
Compile errors with "The right-hand side of 'for ... in' ...".

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions