Skip to content
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

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

Closed
ghost opened this issue Aug 1, 2018 · 3 comments
Closed

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

ghost opened this issue Aug 1, 2018 · 3 comments
Assignees
Labels
Domain: Mapped Types The issue relates to mapped types Question An issue which isn't directly actionable in code

Comments

@ghost
Copy link

ghost commented Aug 1, 2018

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

@ghost ghost added the Domain: Mapped Types The issue relates to mapped types label Aug 1, 2018
@RyanCavanaugh
Copy link
Member

@andy-ms I can't repro on master - any additional details needed?

@ahejlsberg
Copy link
Member

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

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Aug 6, 2018
mike-north added a commit to mike-north/DefinitelyTyped that referenced this issue Sep 15, 2018
mike-north added a commit to mike-north/DefinitelyTyped that referenced this issue Sep 15, 2018
RyanCavanaugh pushed a commit to DefinitelyTyped/DefinitelyTyped that referenced this issue Sep 17, 2018
- [x] Use a meaningful title for the pull request. Include the name of the package modified.
- [x] Test the change in your own code. (Compile and run.)
- [x] Add or edit tests to reflect the change. (Run with `npm test`.)
- [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request).
- [x] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes).
- [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present).

If changing an existing definition:
- [x] Provide a URL to documentation or source code which provides context for the suggested changes: https://www.emberjs.com/api/ember/3.4/functions/@ember%2Fobject/set
- [x] Increase the version number in the header if appropriate.
- [x] If you are making substantial changes, consider adding a `tslint.json` containing `{ "extends": "dtslint/dt.json" }`.

---
- Fixes typed-ember/ember-cli-typescript#308
- Workaround due to breaking change microsoft/TypeScript#26120
- Would much much cleaner w/ a fix for microsoft/TypeScript#27014
@typescript-bot
Copy link
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
Labels
Domain: Mapped Types The issue relates to mapped types Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants