We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? # to your account
narrowing intersection property type guard assertion
occurs on: 5.3.3 5.4.0-dev.20240204
https://www.typescriptlang.org/play?ts=5.4.0-dev.20240204#code/JYOwLgpgTgZghgYwgAgILIN4Chm+QDwH4AuZEAVwFsAjaAbiwF8tRJZEUAhZCfSEACYBnNJhx58pCjXpMsWGORAIwwAPYhkMABRxSqAJRi8yYDGTawATwAOENebgA6fMgC8H5ACJptKF4NsExNyIQgAOSo-XRcDOmQAegTkNQBrcWDkUIhOXTjE5OgoNSgM5GZmBSUVdU1s3OpSTiNsOSrlVQ0ssMiZKG1JMijoQPlKpNNwaDCaroA3adqsaztkAGF3YwkSIb6GZhWUABFNjYAyLdxB31lKxQ7arQBmbQRSNZayswtDh2QEFzuTw+Yb+UaZXDZXrRAH4fITNJlEJhI6veGFKDFUomCrye6zOoo7QCUhHT5yIA
interface A { x?: number; } interface B extends A { x: number; } function f(a: A) { if (typeof a.x === "number"){ useNumber(a.x); // ok useB(a); // error } } function useB(b: B) {} function useNumber(x: number) {}
Cannot assign a to parameter of type B. It seems type narrowing works independently on a.x and a.
a
B
a.x
a should be assignable to parameter of type B.
No response
The text was updated successfully, but these errors were encountered:
Duplicate of #42384 and many many others.
Sorry, something went wrong.
oops @MartinJohns beat me to it this time
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No branches or pull requests
π Search Terms
narrowing intersection property type guard assertion
π Version & Regression Information
occurs on:
5.3.3
5.4.0-dev.20240204
β― Playground Link
https://www.typescriptlang.org/play?ts=5.4.0-dev.20240204#code/JYOwLgpgTgZghgYwgAgILIN4Chm+QDwH4AuZEAVwFsAjaAbiwF8tRJZEUAhZCfSEACYBnNJhx58pCjXpMsWGORAIwwAPYhkMABRxSqAJRi8yYDGTawATwAOENebgA6fMgC8H5ACJptKF4NsExNyIQgAOSo-XRcDOmQAegTkNQBrcWDkUIhOXTjE5OgoNSgM5GZmBSUVdU1s3OpSTiNsOSrlVQ0ssMiZKG1JMijoQPlKpNNwaDCaroA3adqsaztkAGF3YwkSIb6GZhWUABFNjYAyLdxB31lKxQ7arQBmbQRSNZayswtDh2QEFzuTw+Yb+UaZXDZXrRAH4fITNJlEJhI6veGFKDFUomCrye6zOoo7QCUhHT5yIA
π» Code
π Actual behavior
Cannot assign
a
to parameter of typeB
. It seems type narrowing works independently ona.x
anda
.π Expected behavior
a
should be assignable to parameter of typeB
.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: