Skip to content

Array mapped type change breaks ember array 'get' #26120

Description

TypeScript Version: 3.1.0-dev.20180801
(works in 3.1.0-dev.20180731)

Code

Simplified from the compile error in DefinitelyTyped/types/ember:

type ComputedPropertyGetters<T> = { [K in keyof T]: ComputedProperty<T[K]> | T[K] };

declare class ComputedProperty<T> { t: T; }

interface Array<T> {
    get<T, K extends keyof T>(this: ComputedPropertyGetters<T>, key: K): T[K];
    firstObject: ComputedProperty<T | undefined>;
}

const n: number | undefined = [0].get("firstObject");

Expected behavior:

No error.

Actual behavior:

src/a.ts:10:7 - error TS2322: Type 'ComputedProperty<number | undefined>' is not assignable to type 'number'.

10 const n: number | undefined = [0].get("firstObject");

The intention was for the following type arguments to be inferred:

[0].get<{ firstObject: number | undefined }, "firstObject">("firstObject");

The code still works when the above type is explicitly provided.

I think this change is due to #26063 (CC Anders Hejlsberg (@ahejlsberg)).

Activity

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

Metadata

Metadata

Labels

Domain: Mapped TypesThe issue relates to mapped typesQuestionAn issue which isn't directly actionable in code

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions