Skip to content

Type rules are not followed for parent classes with generic types and child class fields #55113

Description

@RobertSandiford

Bug Report

Child class, fields, properties, generic class inheritance, type rules, additional properties in objects

Child class fields do not follow type rules

🕗 Version & Regression Information

Seen in 4.9.5 + 5.1.6. Not aware of a version without it.

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about anything relevant

⏯ Playground Link

Playground

💻 Code

classP<T>{t?: T}typeU={a: numberb: number}classC1extendsP<U>{t={// expected error, b is missinga: 1,}}constu: U={a: 1,b: 2,c: 3// expected error, c is additional}classC2extendsP<U>{t={a: 1,b: 2,c: 3// unexpectededly allowed}}

🙁 Actual behavior

The (object with 1 property) assigned to C1.t does not match the type U. As expected.
The (object with 3 properties) assigned to u does not match the type U. As expected.
However the (object with 3 properties) can be assigned to C2.t without an error. Not expected.

🙂 Expected behavior

Assignments to P.t (t is type U) to behave in the same was as assignments to u (type U), type error thrown at line 26

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