1

I am having the following code in typescript :

export class Custom {
     [k: string]: any // Index Signature

     // parameters example
     // let o:Object = {"blah":1, "foo": "lol"}
     // let arr: Array<string> = ["blah", "foo"]
    constructor(o: Object, p: Array<string>)
     for(let prop of arr) {
        let p: any = (<any>o)[prop]
        if (p !== undefined) {
            this[prop] = p
        }
      }
}

I keep having TS7017 Index signature of object type implicitly has an 'any' type on this[prop] = p

Thanks !

Edit : Adding the index signature solved my problem.

Scipion
  • 11,449
  • 19
  • 74
  • 139

1 Answers1

4

TS7017 Index signature of object type implicitly has an 'any' type

Whatever this is in that code, it does not have an index signature (so implicit any).

Quick Fix

  • Switch off noImplicitAny till you get more comfortable working with TypeScript.
basarat
  • 261,912
  • 58
  • 460
  • 511
  • I am gonna edit my post to include this, which is only a simple class. However, I'd be very interested into seeing how to create an index signature. – Scipion May 31 '16 at 07:11
  • 1
    Thanks the Index Signature fixed my problem. – Scipion May 31 '16 at 08:00