2

With this TypeScript (based on some online course):

interface IProduct {
    productName: string
}

interface IProductResource extends ng.resource.IResource<IProduct> {
}

interface IDataAccessService {
    getProductService(): ng.resource.IResourceClass<IProductResource>
}

class DataAccessService implements IDataAccessService {
    static $inject = ['$resource'];

    constructor(private $resource:ng.resource.IResourceService) {
    }

    getProductService():ng.resource.IResourceClass<IProductResource> {
        return this.$resource("sampleUrl");
    }

}

angular.module('app').service('dataAccessService', DataAccessService);

I have a code that uses dataAccessService:

var obj : IProductResource = dataAccessService.getProductService().get();

obj has all angular's REST helper methods like $save/$delete, but I don't have access to interface obj.productName. What is wrong with this code?

dragonfly
  • 17,407
  • 30
  • 110
  • 219
  • how to define API actions and their definition? surly i need to define it inside this.$resource("sampleUrl"); , but there should be ts definitions too, how to do that? – Hassan Faghihi Jan 26 '17 at 20:16

1 Answers1

2

I think I got it. It should be:

interface IProductResource
    extends ng.resource.IResource<IProduct>, IProduct {
}

Any comments on that?

Thanks!

dragonfly
  • 17,407
  • 30
  • 110
  • 219