Open Nodonisko opened 1 year ago
Why it's neccessary
because TS doesn't infer the type correctly in this specific case and it points to (for instance) string | undefined
instead of Option<string>
Enabling noUncheckedIndexedAccess in our codebase is not a option because it will throw like in milion places.
to me having this option enabled is a must-have for any TS project, it provides another layer of safety (and in my opinion, this option should be enabled by default in TS)
Thanks for explanation. I agree with better safety, but enabling it in legacy project is nearly impossible.
Played with it little bit more, but noUncheckedIndexedAccess
doesn't seems to work with anything that string literals for object/array keys.
const { min, max } = getMinMaxIndex(arrayOfNumbers);
if(arrayOfNumbers[min]) {
// this will throw anyway because of noUncheckedIndexedAccess
console.log(arrayOfNumbers[min])
}
There is lot of opened issues about this for years in TS repo but it doesn't seems to move anywhere. But it's probably no big deal for us we can go with Result
in most cases.
Hi, I am using ts-belt in legacy code-base and there is this message in docs:
Why it's neccessary, will it not work at all or it will break in some cases? Enabling
noUncheckedIndexedAccess
in our codebase is not a option because it will throw like in milion places.