Skip to content

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

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

Closed
apr-xaml opened this issue Sep 1, 2017 · 3 comments
Closed

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

apr-xaml opened this issue Sep 1, 2017 · 3 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@apr-xaml
Copy link

apr-xaml commented Sep 1, 2017

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' ...".

@mhegazy mhegazy added the Bug A bug in TypeScript label Sep 5, 2017
@mhegazy mhegazy added this to the TypeScript 2.6 milestone Sep 5, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 5, 2017

T extends object or T extends {} should avoid the error for now.

@gcnew
Copy link
Contributor

gcnew commented Sep 5, 2017

Please, don't fix the new correct behaviour. It's been a bug in the compiler that has allowed this unsafe iteration.

@mhegazy mhegazy modified the milestones: TypeScript 2.6, TypeScript 2.7 Oct 9, 2017
@mhegazy mhegazy modified the milestones: TypeScript 2.7, TypeScript 2.8 Jan 9, 2018
@mhegazy mhegazy modified the milestones: TypeScript 2.8, TypeScript 2.9 Mar 9, 2018
@mhegazy mhegazy modified the milestones: TypeScript 2.9, Future Apr 26, 2018
@RyanCavanaugh
Copy link
Member

Agreed, this doesn't seem like a bug.

@RyanCavanaugh RyanCavanaugh closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants