Skip to content

Lookup types and polymorphic this issue #12723

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
dsehnal opened this issue Dec 7, 2016 · 3 comments · Fixed by #12770
Closed

Lookup types and polymorphic this issue #12723

dsehnal opened this issue Dec 7, 2016 · 3 comments · Fixed by #12770
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@dsehnal
Copy link

dsehnal commented Dec 7, 2016

TypeScript Version: 2.1.4

Code

interface A<T> { value: T }
interface B extends A<string> { }

abstract class C<T extends A<any>> {
    private t: T;
    get a(): this['t']['value'] { return this.t.value };
}

class D extends C<B> {
    get b() { return this.a; }
}

Expected behavior:

I would expect that the type of D.b would be string.

Actual behavior:

Type of D.b is any

@dsehnal
Copy link
Author

dsehnal commented Dec 7, 2016

Here is a more simplified version of the issue:

interface A<T> { t: T }
function f<T extends A<any>>(t: T['t']): T {
    return { t };
}

Here t is of type any instead of T['t']. So I suppose that what's going on is that T['t'] is evaluated immediately instead of keeping the generic value.

So my question would be: Will the type system ever support this behaviour?

@mhegazy
Copy link
Contributor

mhegazy commented Dec 7, 2016

This is a bug, should be fixed shortly.

@mhegazy mhegazy added the Bug A bug in TypeScript label Dec 7, 2016
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Dec 8, 2016
@ahejlsberg
Copy link
Member

The issue is fixed by #12770, but note that your example only works if you remove the private modifier from t because indexed access types only operate on public properties.

@mhegazy mhegazy added this to the TypeScript 2.1.5 milestone Jan 3, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants