0

I'm having a bit of trouble figuring out how to write a type definition for the following code. I guess the best way to describe it is a static class that contains a named constructor.

var ajaxAdapter = new IAjaxAdapter.implement({
   ajax: function (work: IAjaxRequest) {
      ...
   }
}

But I'm getting an build error Property 'implement' does not exist on type 'typeof IAjaxAdapter'.

My d.ts looks like this right now but obviously it's a bit wrong

export class IAjaxAdapterInstance {
    constructor(any: any);
    ajax: (request: IAjaxRequest) => void;
}
export class IAjaxAdapter {
    implement: IAjaxAdapterInstance;
}

I'm not sure if this is possible, if not I guess I could any type it... but I was hoping for something.

1 Answer 1

1

Just looking at the types, since you're using implement as a static property that refers to a class rather than an object, it should type if you add a static and a typeof:

export class IAjaxAdapter {
    static implement: typeof IAjaxAdapterInstance;
}
Sign up to request clarification or add additional context in comments.

1 Comment

That worked beautifully! Also, I had no idea you could use static and typeof in a definition file, yay learning!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.