EDIT: As someone pointed out, this has to do with the asynchronous nature of the console, and an answer can be found here: Weird behavior with objects & console.log
I have an issue where JS will correctly detect an iterator, yet will not be able to directly access its properties: I know this because I can console.log() the iterator, which will correctly return a non-empty result with size > 0, yet if I console.log() the iterator.size, I get 0. There are no error messages.
Here, listOfLabelLists
is of type Set<string>[]
, although I've tried converting its elements from sets to maps and arrays, with the same result: I can log labelList
correctly, but logging just its size/length property returns 0, and so the code (commented below) is never read.
listOfLabelLists.forEach(labelList => {
//console.log(labelList) returns a set with size 7.
//console.log(labelList.size) returns 0.
labelList.forEach(wordLabel => {//This never runs because the set is interpreted as empty.
...
})
})
I wrote this code in TypeScript, so I wondered if it was compiling incorrectly. However, after running tsc on the file to output the JS formatted version, it looks like TypeScript is not at fault here, as the relevant JS portion was identical.