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

Incorrect extend errors since v2.4 update #17123

Closed
samchon opened this issue Jul 12, 2017 · 6 comments
Closed

Incorrect extend errors since v2.4 update #17123

samchon opened this issue Jul 12, 2017 · 6 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@samchon
Copy link

samchon commented Jul 12, 2017

I've been publishing a library compiled by the TypeScript. Since the v2.4 update, my library fails to compile throwing such error:

error TS2415: Class 'MapContainer<Key, T>' incorrectly extends base class 'Container<Pair<Key, T>>'.
error TS2415: Class 'MapIterator<Key, T>' incorrectly extends base class '_ListIteratorBase<Pair<Key, T>>'.
error TS2344: Type 'SetIterator<T>' does not satisfy the constraint '_ListIteratorBase<T>'.
...
...

It was not a problem to extending a class and overriding some methods to return (or get parameter) sub-type of origin. Thus, below example code, there hasn't been any error until the v2.3. However, since the v2.4 update, below code throws incorretly extends base class error.

I want to know that such errors, since v2.4, are by whether:

  1. intended error of TypeScript-compiler; stricter type checking
  2. domain error of mis-update.
namespace std.base
{
    //------------------------------------------------
    // ABSTRACT CLASSES
    //------------------------------------------------
    export abstract class Container<T>
    {
        public abstract begin(): Iterator<T>;
        public abstract end(): Iterator<T>;
        public erase(first: Iterator<T>, last: Iterator<T>): Iterator<T>;
    }
    export abstract class Iterator<T>
    {
        public abstract source(): Container<T>;
        public abstract prev(): Iterator<T>;
        public abstract next(): Iterator<T>;
    }
}

namespace std
{
    //------------------------------------------------
    // DERIVED CLASSES
    //------------------------------------------------
    // DERIVED CONTAINERS
    export class Vector<T> extends base.Container<T>
    {
        public begin(): VectorIterator<T>;
        public end(): VectorIterator<T>;
        public erase(first: VectorIterator<T>, last: VectorIterator<T>): VectorIterator<T>;
    }
    export class List<T> extends base.Container<T>
    {
        public begin(): ListIterator<T>;
        public end(): ListIterator<T>;
        public erase(first: ListIterator<T>, last: ListIterator<T>): ListIterator<T>;
    }

    // DERIVED ITERATORS
    export class VectorIterator<T> extends base.Iterator<T>
    {
        public source(): Vector<T>;
        public prev(): VectorIterator<T>;
        public next(): VectorIterator<T>;
    }
    export class ListIterator<T> extends base.Iterator<T>
    {
        public source(): List<T>;
        public prev(): ListIterator<T>;
        public next(): ListIterator<T>;
    }
}
@ghost
Copy link

ghost commented Jul 12, 2017

Noticed this:

abstract class Container<T> {
    erase<U extends T>(begin: Iterator<U>, end: Iterator<U>): Iterator<T>;
}

abstract class SetContainer<T> extends Container<T> {
    erase(begin: SetIterator<T>, end: SetIterator<T>): SetIterator<T>;
}

You need erase<U extends T> in the subclass to have a compatible signature. This is a new error due to #16368. Previously we would squash all generics to any before comparing signatures.

@MatejQ
Copy link

MatejQ commented Aug 22, 2017

I am getting this "incorrectly extends..." error too. However, my classes are not that simple and I cannot seem to be able to identify what exactly is wrong. It compiled fine in TypeScript 2.3. Is it possible to include more specific reason why TypeScript thinks it incorrectly extends parent class?

@ghost
Copy link

ghost commented Aug 22, 2017

@MatejQ Usually TypeScript will drill down into the method that extends the base method incorrectly; maybe the tool you're using to display errors is hiding this? Try running tsc from the command line?

@MatejQ
Copy link

MatejQ commented Aug 22, 2017

@andy-ms thanks, that really helped. I had to set the output of MSBuild in visual studio to detailed and then I got all the specific messages from tsc. I hope this helps someone else too.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Aug 22, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Aug 22, 2017

based on #17123 (comment), this seems like the expected behavior.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 7, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Sep 7, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants