A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Microsoft/TypeScript/issues/1425 below:

Contextual type does not flow into a super call if it is based on a type argument to the base class · Issue #1425 · microsoft/TypeScript · GitHub

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4