Skip to content

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

Description

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;
}

Activity

  1. JsonFreeman commented on Dec 10, 2014

    @JsonFreeman
    ContributorAuthor

    Possibly related to #1424

  2. DanielRosenwasser commented on Jan 21, 2015

    @DanielRosenwasser
    Member

    Seems possibly related to #1480.

  3. DanielRosenwasser commented on Jan 28, 2015

    @DanielRosenwasser
    Member

    I think this should be fixed in #1816.

  4. DanielRosenwasser commented on Jan 28, 2015

    @DanielRosenwasser
    Member

    Also, is this really a breaking change?

  5. JsonFreeman commented on Jan 28, 2015

    @JsonFreeman
    ContributorAuthor

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

  6. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Breaking ChangeWould introduce errors in existing codeBugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions