Answer the question
In order to leave comments, you need to log in
How to handle such an exception using TS?
type Item = {
title: string
}
const arr : Item[] = []
const a = arr[0].title.length //error , но TS молчит
Answer the question
In order to leave comments, you need to log in
const arr1 : [Item, ...Item[]] = [{ title: 'a' }] // OK
const arr2 : [Item, ...Item[]] = [] // Не скомпилируется
If TS is higher than 4.1 then add to tsconfig.json in compilerOptions:
"noUncheckedIndexedAccess": true
TS will complain about unchecked index access
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question