Skip to content

Type must have a '[Symbol.iterator]()' method that returns an iterator. #10574

@kwojcik-blockether

Description

@kwojcik-blockether

TypeScript Version: 1.8.10

Code

let MyObject = {
    'a': 'Hello',
    'b': 'it\'s',
    'c': 'me',
    'd': 'you',
    'e': 'looking',
    'f': 'for'
};
MyObject[Symbol.iterator] = function* () {
    let properties = Object.keys(this);
    for (let i of properties) {
        yield [i, this[i]];
    }
}
for (let [k, v] of MyObject) {
    console.log(`Here is key ${k} and here is value ${v}`);
}

Expected behavior:
I want this code to pass without error but I do not now how can i do it.
If i try to run the .js code it works just fine and prints this output:

Here is key a and here is value Hello
Here is key b and here is value it's
Here is key c and here is value me
Here is key d and here is value you
Here is key e and here is value looking
Here is key f and here is value for

Actual behavior:
The error message is:
Type must have a 'Symbol.iterator' method that returns an iterator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions