TSConfig
noUncheckedIndexedAccess
TypeScript has a way to describe objects which have unknown keys but known values on an object, via index signatures.
tsTryinterfaceEnvironmentVars {NAME : string;OS : string;// Unknown properties are covered by this index signature.[propName : string]: string;}declare constenv :EnvironmentVars ;// Declared as existingconstsysName =env .NAME ;constos =env .OS ;// Not declared, but because of the index// signature, then it is considered a stringconstnodeEnv =env .NODE_ENV ;
Turning on noUncheckedIndexedAccess will add undefined to any un-declared field in the type.
tsTrydeclare constenv :EnvironmentVars ;// Declared as existingconstsysName =env .NAME ;constos =env .OS ;// Not declared, but because of the index// signature, then it is considered a stringconstnodeEnv =env .NODE_ENV ;