Skip to content

Cannot use 'this' type in type argument on base types #7289

@DanielRosenwasser

Description

@DanielRosenwasser
interface Foo<T> {
    thing: T;
}

interface Bar extends Foo<this> {
    thing: this;
}
class Foo<T> {
    thing: T;
}

class Bar extends Foo<this> {
    thing: this;
}
interface Foo<T> {
    thing: T;
}

class Bar implements Foo<this> {
    thing: this;
}

These examples have an error on the 'this' type argument of Foo:

TS2526  A 'this' type is available only in a non-static member of a class or interface.

Since an object type cannot reference a type parameter directly within a heritage clause, we shouldn't be giving this error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions