Skip to content

Type error with 'extends' constraint and inheritance #17316

Closed
@remagpie

Description

@remagpie

TypeScript Version: 2.4.1

Code

interface A {
  a: number;
}

interface B extends A {
  b: number;
}

function x(b: B): void {}
const y: <C extends A>(c: C) => void = x;

Expected behavior:
No Type Error

Actual behavior:
Type error with message :

Type '(b: B) => void' is not assignable to type '<C extends A>(c: C) => void'.
  Types of parameters 'b' and 'c' are incompatible.
    Type 'C' is not assignable to type 'B'.
      Type 'A' is not assignable to type 'B'.
        Property 'b' is missing in type 'A'.

Comment
Weirdly, it doesn't show any errors on Playground, but it shows errors when compiled on local project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions