Fatema tuz johura
Fatema tuz johura

Reputation: 141

Can't Use generator in nodejs typescript

here is my typscript code -

export default class CModel{
    CName:string;
    [Symbol.iterator]: function* () { 
        yield 1;
      }  

}

here is my error list-

  1. cModel[Symbol.iterator] is not a function.
  2. Can not find name function.

Upvotes: 1

Views: 59

Answers (1)

Estus Flask
Estus Flask

Reputation: 222548

[Symbol.iterator]: ... designates a type, doesn't assign a value. function* () { ... } is not a type, it's actual function.

If the intention is to assign Symbol.iterator property on class instance, it should be:

export default class CModel{
    CName:string;

    [Symbol.iterator] = function* () { 
        yield 1;
    }  
}

Upvotes: 1

Related Questions