-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Different behavior between const and readonly for multidimensional array access/strict null checking #58476
Comments
Especially on the playground it's easy to test this on prior versions because the playground has a version selector on the top left. |
I was unaware of that. Thanks for letting me know. I tested it back a few versions and they all produce the same errors. |
This is working as intended. A |
function itsaFunction(arrayAccessors: readonly number[])
{
let someArray: Array<Array<Array<number | null> | null> | null> = new Array<Array<Array<number | null> | null> | null>();
const arrAcc1 = arrayAccessors[0];
const arrAcc2 = arrayAccessors[1];
if (someArray[arrAcc1] !== null && someArray[arrAcc1][arrAcc2] != null)
console.log(arrayAccessors);
} Strangely, this doesn't work, either. Gives the same error. |
This works in 5.5 beta. For more information, see https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-beta/#control-flow-narrowing-for-constant-indexed-accesses |
Thanks for the info. Good to know this is at least being addressed. |
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
🔎 Search Terms
different behavior between readonly and const
🕗 Version & Regression Information
⏯ Playground Link
No response
💻 Code
🙁 Actual behavior
Errors about possible null values do not treat const and readonly the same
🙂 Expected behavior
const and readonly should produce/fix the same errors in the same way
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: