-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Array.isArray type guard does not match arrays with readonly modifiers #55238
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
Suggested solution (this would fix the scenario, not sure if it doesn't break sth else, though :P ):
(note the |
Duplicate of #53395, in which this is considered to be working as intended and I disagree 😄 |
Yeah, that one flew by me. I also disagree with that decision, I think. I find it difficult to worry about a non- |
Filing this under the "People generally say TypeScript should be more strict but specifically want possibly-wrong but convenient answers" folder 😉 |
@RyanCavanaugh FWIW this issue is actually a good example of when it's more or less impossible for TypeScript to be sound - given how TypeScript works, Footnotes
|
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
Array.isArray
, when used on a type union, does not result in a positive type guard match on array types that are declaredreadonly
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
🙁 Actual behavior
After testing a
readonly T[] | V
-typed variable withArray.isArray()
, acessingV
-exclusive properties without a cast still yields an error, as the LHS of the union type is not ruled out. ('Property does not exist on type readonly T[]')In contrast,
T[] | V
- typed variables don't have this problem.🙂 Expected behavior
The behaviour should be consistent for both
readonly
and non-readonly
variantsThe text was updated successfully, but these errors were encountered: