You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No error is caught by static analysis, and each function is allowed to access & modify x.d despite it not existing in the value of x that they are given.
π Expected behavior
A "not assignable to type" error should be raised when trying to pass either function an object that partially implements TPart2, even if that object fully implements TPart1.
Alternatively, the presence of any property of TPart2 on the object shouldn't assume the presence of all other properties of TPart2 on that object.
Additional information about the issue
When an object fully satisfies a particular interface/type and partially satisfies another, that object is considered to satisfy the union of the fully-satisfied type & the partially-satisfied one.
However, this breaks the assumption that if the object has any property of the partially-satisfied interface/type, it must have all of them.
A way around this is to distinguish types by adding tag properties to them Γ la discriminated unions, but this requires runtime-visible changes to objects that could perhaps be avoided by stricter static analysis.
The text was updated successfully, but these errors were encountered:
A "not assignable to type" error should be raised when trying to pass either function an object that partially implements TPart2, even if that object fully implements TPart1.
π Search Terms
union member in partial
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.3.0-dev.20230828#code/JYOwLgpgTgZghgYwgAgCoAU5TARmQbwChkTk4AuZEAVwFsAjaAbmNPspoecIF9DDQkWIhQYsYAEwFWJBBzqMoLUsgAm8rkt78EAexABnMMgAO4nAH04IVRbPZgcADZ3xUgLzSVFZDgA0MsjsyBIBKnLIAMwBfIQw1CAIYMD6yDAWYtg4APJQEgAUAB6UmbgAPqUSAJRepMAwyPkA5AhNyKDIhTVEKiqFAHSqyABUnhLKpHzh+ga6ThD9TroA5kVVLHzppTl5+fa4VjauDs7Hkuv8gtDwSGgAQrpgABbIEIWQNgZomFl+324EPhgACeJlEP1wuQez2Qnm2yDK90eTxY8USyVSWwhO2hTyKJWxUOR3UC9UaLTaHS6tV6nUGIzGExIU1IekMcwWS1WXQ2cQyhKguL25kOtn2jhc+2qLEIILB-yyuQAkuBoAYIEkUiBYQrcAjGvCAGS66VxBKazH88zK1VQdUWkD43U7FVCe0YkAklRk5qtdra6k9Wl0oajEJM5As2QzDmLFZrXlY61QV1qjUe4VZUVnCVnU2y0Hg8wAQRsAFk4MDGBCPM7kMb8pV9fgeBc0Q60lasqXVBWqxAa07tj2+9W3F66g1fZSAxPaQNQ4zAlHkGzZvM49yLpsu7gR5Wx9gCvtLNYxeJc1L1kA
π» Code
π Actual behavior
No error is caught by static analysis, and each function is allowed to access & modify
x.d
despite it not existing in the value ofx
that they are given.π Expected behavior
A "not assignable to type" error should be raised when trying to pass either function an object that partially implements
TPart2
, even if that object fully implementsTPart1
.Alternatively, the presence of any property of
TPart2
on the object shouldn't assume the presence of all other properties ofTPart2
on that object.Additional information about the issue
When an object fully satisfies a particular interface/type and partially satisfies another, that object is considered to satisfy the union of the fully-satisfied type & the partially-satisfied one.
However, this breaks the assumption that if the object has any property of the partially-satisfied interface/type, it must have all of them.
A way around this is to distinguish types by adding tag properties to them Γ la discriminated unions, but this requires runtime-visible changes to objects that could perhaps be avoided by stricter static analysis.
The text was updated successfully, but these errors were encountered: