0

I'm using typescript and angular on a project. When i want to expose service's method i do the following :

export class MyService implements IService {

    //Public method
    public myMethod: Function;

    public constructor() {

        this.myMethod= this._myMethod;

    }

    private _myMethod(): void {
       //...
    }

When i work on service which get many method, i don't have to scroll to see method's definition so that's great. But now when i'm using my service's method in another service or controller, i can't see signature of my method... So i'm loosing typescript advantages...

Any idea ?

Thanks.

4
  • 1. Are the methods listed in the IService interface ? 2. Are you declaring the injected service in the controller to be of type IService ? Commented Feb 5, 2015 at 10:10
  • No, currently i'm not using IService. Commented Feb 5, 2015 at 10:25
  • That's why you're not seeing the signature/intellisense. You need to specify on your declaration in the DI in the controller that your service is of the type you say it is. Commented Feb 5, 2015 at 10:31
  • Meaning function (myService: IService) {...} Commented Feb 5, 2015 at 10:32

1 Answer 1

1

The simple answer is that you need to give your function definition a signature

class MyService {
    public myMethod: () => void; //don't use Function

    constructor() {
        this.myMethod = this.myMethod;
    }

    _myMethod = () => {

    }

}

However a better approach is to define an interface:

interface IMyService extends IService {
    myMethod: () => void;
}

class MyService implements IMyService {
    constructor() {

    }

    myMethod = () => {

    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.