Reputation: 2591
i Am having a problem in typeScript + angular , here class foo is a service which is using another service as fooService and fooServie.getUser() is returning a promise of some type
compilation is good but with this type error :TS2409: Return type of constructor signature must be assignable to the instance type of the class
Pleae help me out with the issue
module fooModule {
export class foo {
static $inject = ['fooService'];
constructor(public fooService:services.fooService) {
return fooService.getUser();
}
}
}
Upvotes: 0
Views: 8444
Reputation: 276115
compilation is good but with this type error :TS2409: Return type of constructor signature must be assignable to the instance type of the class
The error is very clear. The return statement from the constructor return fooService.getUser();
should give an instance of the class class foo
. e.g.
declare class FooService{
getfoo():foo;
}
class foo {
constructor(public fooService:FooService) {
return fooService.getfoo();
}
}
Otherwise in var f = new foo
the variable f
would not be of type foo
.
I am not sure what you intent is but hopefully this will guide you more:
module fooModule {
export class Foo {
static $inject = ['fooService'];
constructor(public fooService:services.FooService) {
}
getUser():ng.IPromise<User>{
return this.fooService.getUser();
}
}
var foo = new Foo();
foo.getUser().then(()=>{
// complete this code here
});
}
Upvotes: 2