Skip to content

The info that generic type extends some type is lost during inheritance #18156

Closed
@astashov

Description

@astashov

TypeScript Version: 2.4.2

Code

class Value<T> {
  constructor(protected readonly data: T) {}

  public bar(data: Partial<T>): this {
    return this;
  }
}

interface Type {
  foo: string;
}

class TheClass<T extends Type> extends Value<T> {
  public foo(): this {
    return this.bar({foo: "d"});
  }
}

Expected behavior:

No errors, since it should be aware T extends Type, which has foo.

Actual behavior:

Shows an error:

Argument of type '{ foo: "d"; }' is not assignable to parameter of type 'Partial<T>'.

Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions