-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed as not planned
Closed as not planned
Copy link
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
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
💻 Code
class P<T> {
t?: T
}
type U = {
a: number
b: number
}
class C1 extends P<U> {
t = { // expected error, b is missing
a: 1,
}
}
const u: U = {
a: 1,
b: 2,
c: 3 // expected error, c is additional
}
class C2 extends P<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
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug