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

Contextual type does not flow into a super call if it is based on a type argument to the base class #1425

Closed
JsonFreeman opened this issue Dec 10, 2014 · 5 comments
Assignees
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@JsonFreeman
Copy link
Contributor

If you extend a generic class and pass a type argument, the instantiated constructor of the base class fails to contextually type the argument of a super call. This works correctly for base class methods, and it works correctly for constructors if the contextual type is not based on a type argument that was passed in the extends clause.

class C extends CBase<string> {
    constructor() {
        // Does not work
        super({
            method(p) { p.length; } // Error
        });

        // Works
        super.foo({
            method(p) { p.length; }
        });
    }
}

class CBase<T>  {
    constructor(param: ContextualType<T>) { } // Works if you change this to ContextualType<string>
    foo(param: ContextualType<T>) { }
}

interface ContextualType<T2> {
    method(parameter: T2): void;
}
@JsonFreeman JsonFreeman added the Bug A bug in TypeScript label Dec 10, 2014
@JsonFreeman
Copy link
Contributor Author

Possibly related to #1424

@JsonFreeman JsonFreeman added the Breaking Change Would introduce errors in existing code label Dec 10, 2014
@sophiajt sophiajt added this to the TypeScript 2.0 milestone Jan 12, 2015
@DanielRosenwasser
Copy link
Member

Seems possibly related to #1480.

@DanielRosenwasser
Copy link
Member

I think this should be fixed in #1816.

@DanielRosenwasser
Copy link
Member

Also, is this really a breaking change?

@JsonFreeman
Copy link
Contributor Author

Yeah it is a breaking change in 1.1 because the old compiler did not have this bug.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants