The "noUncheckedIndexedAccess" is the most awesome config option you've never heard of. It makes accessing objects a lot safer, and also powers up TypeScript's inference on objects.
export const myObj: Record<string, string[]> = {};
myObj.foo.push("bar") // no error
Add "noUncheckedIndexedAccess": true
to tsconfig.json,
TS is smart enough if you do:
export const myObj: Record<string, string[]> = {};
if (!myObj.foo) {
myObj.foo = [];
}
myObj.foo.push("bar"); // fine again
标签:noUncheckedIndexedAccess,Typescript,Make,objects,accessing,myObj,foo,tsconfig From: https://www.cnblogs.com/Answer1215/p/16801259.html