javascripttypescripttype-declarationtype-definition

Is there a way to add Types Definition/Declaration for bind functions?


I'm learning TypeScript now and I have been wanting to create and contribute my own Type Def File.

So I was having trouble lately to get the Intellisense to work with the type because of this binding function

declare module 'jshue' {
    export interface IHue {
        discover: () => Promise<Array<any>>,
        bridge: (ip: string) => any
    }
    var jsHue:IHue = jsHueAPI.bind(null, fetch, Response, JSON, Promise);
    export default jsHue;
}

The problem with this is that when I import the library and try to use it, an error message will be prompted saying that

This expression is not callable.
Type 'IHue' has no call signatures.

It will work if I declare a type when declaring jsHue, It's just that it will defeat the purpose of having type definition file.

import jsHue, { IHue } from 'jshue';
const hue:IHue = jsHue();

Also, is there a way that I could avoid declaring a new variable with jsHue()?

Is there any other solution for this to work?

JS Library for jsHue


Solution

  • Resolved with the help from Bergi Solution here https://github.com/blargoner/jshue/pull/23