Skip to content

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

Closed
@ghost

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 @ahejlsberg).

Activity

ghost added on Aug 1, 2018
RyanCavanaugh

RyanCavanaugh commented on Aug 3, 2018

@RyanCavanaugh
Member

@Andy-MS I can't repro on master - any additional details needed?

ahejlsberg

ahejlsberg commented on Aug 6, 2018

@ahejlsberg
Member

@DanielRosenwasser Looks to me like we're doing the right thing here. You mentioned you'd discuss with the Ember folks.

typescript-bot

typescript-bot commented on Jul 13, 2019

@typescript-bot
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

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

      Participants

      @DanielRosenwasser@ahejlsberg@RyanCavanaugh@typescript-bot

      Issue actions

        Array mapped type change breaks ember array 'get' · Issue #26120 · microsoft/TypeScript