donnut
donnut

Reputation: 720

Typescript definition of function with property

I'm writing a d.ts file for ramda. The lib has a function mapObj and mapObj.idx.

interface RamdaStatic {
 ...
  mapObj(
    fn: Function,
    obj: any
  ): any;
  ...
}

My question is how to add mapObj.idx that has a similar type def? I am aware of answer, but that requires a seperate interface and I would like to avoid that.

Upvotes: 1

Views: 427

Answers (1)

user1233508
user1233508

Reputation:

Instead of saying "mapObj is a function", say "mapObj can be called like a function and it has additional properties":

interface RamdaStatic {
  // ...
  mapObj: {
    (fn: (value: any) => any, obj: any): any;
    idx: (fn: (value: any, key: string, obj: any) => any, obj: any) => any;
  }
  // ...
}

You might be able to add more type parameters to this definition to make it more useful.

Upvotes: 2

Related Questions