Skip to content

Mapped types break for-in loops with intersections #13023

Description

@gcnew

TypeScript Version: nightly

The following used to work but is broken now.

Code

function extend<T, U>(base: T, ext: U): T & U {
    const retval = <T & U> {};

    for (const x in base) {
        // Error: Type 'T[keyof T]' is not assignable to type '(T & U)[keyof T]'.
        retval[x] = base[x];
    }

    for (const x in ext) {
        // Error: Type 'U[keyof U]' is not assignable to type '(T & U)[keyof U]'.
        retval[x] = ext[x];
    }

    return retval;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions