-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Inconsistent incompatible types error for a sparse array type declaration #50351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Rethought about it, I now believe that the correct behavior is that TypeScript should consistently reject it. Because for
|
This is caused by a false positive of
While this looks pretty chaotic, it does finish with the correct results if you bump the
Note that the comparison at index 8 is the result of contextual signature instantiation after a potentially questionable inference explained here. That’s a separate bug, but fixing it would probably prevent this particular example from triggering the depth limiter. |
#58321 fixes this by changing the weird inference mentioned above, but I feel like it’s probably wrong |
@ahejlsberg says possibly related to #56291 and #55666 |
This issue has been marked as "Design Limitation" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
🔎 Search Terms
incompatible types inconsistent
🕗 Version & Regression Information
The behavior changes between 4.4.4 and 4.5.5, but the previous state wasn't the expected result either.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The code above reports:
on
return a;
.However, if the
const _a
line is uncommented, the error goes away. If you move that line to after the generic function, both places report this error.(Weirdly, if you remove the
every
method from theReadonlySparseArray
, both places would be reporting the error regardless of the place of theconst _a
line.)🙂 Expected behavior
It should not report error, since
SparseArray
andReadonlySparseArray
here should be compatible with array type. It's just a declaration of some of its methods.The text was updated successfully, but these errors were encountered: