Why can't I access array immediately after checking the index?

I check that the array index is accessible, but it is still typed as possibly undefined
3 Replies
JessesBeetShoppe
JessesBeetShoppe•2y ago
@Lubricashawn to fix this you can either change to gameBoard[rowIdx]![colIdx] or you can use matt pocock's new tool that address this and a couple of other typescript inconsistencies https://www.youtube.com/watch?v=bUts4HJJjV4&ab_channel=MattPocock
Matt Pocock
YouTube
I fixed TypeScript
I might have fixed TypeScript - or at least, fixed the things I hate most about it - with a library called ts-reset. Yes, that tweet in the thumbnail is real: https://twitter.com/donavon/status/1627713574553387025 Repo: https://github.com/total-typescript/ts-reset Become a TypeScript Wizard with Matt's beginners TypeScript Course: https://ww...
chawnsphone
chawnsphone•2y ago
Yeah I was trying to avoid the non-null assertion, but it seems there's no way around it 🙂 thanks @JessesBeetShoppe !
whatplan
whatplan•2y ago
Yea this is just a flaw of typescript. I’m pretty sure assigning the value at the first index to a variable, then checking that the variable isn’t undefined, and then indexing the variable with the second index will work.
Want results from more Discord servers?
Add your server