'Appending strings to JSON Files

consider the following code snippet:

let proposals = JSON.parse(fs.readFileSync(proposalsFile, "utf8"))
proposals[network.config.chainId!.toString()].push(proposalId.toString())
fs.writeFileSync(proposalsFile, JSON.stringify(proposals))

The initial proposalFile contains the following: { '31337': [] }

I don't understand what is happening in the second line above. How can the index of the array proposals[] be of type String, if indeed it is an array?

What is the meaning of the ! in ChainId!?

Subsequent executions of this script will result in strings getting appended in the proposalFile:

{"31337":["21810620491323861737494108894072031792136914678422989467418569109597477706871","21810620491323861737494108894072031792136914678422989467418569109597477706871"]}

I understand why this is done, I don't understand how the code snippet results in the above JSON file? The original context of this snippet can be found here: https://github.com/PatrickAlphaC/dao-template/blob/main/scripts/propose.ts



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source