@@ -20,11 +20,12 @@ import {
2020 IAttributes ,
2121} from './interfaces' ;
2222
23- export class Service extends ParentResourceService {
23+ export class Service < R extends Resource = Resource > extends ParentResourceService {
2424 public schema : ISchema ;
2525 public cachememory : ICacheMemory ;
2626 public cachestore : CacheStore ;
2727 public type : string ;
28+ public resource = Resource ;
2829
2930 private path : string ; // without slashes
3031 private smartfiltertype = 'undefined' ;
@@ -33,7 +34,7 @@ export class Service extends ParentResourceService {
3334 Register schema on Core
3435 @return true if the resource don't exist and registered ok
3536 */
36- public register ( ) : Service | false {
37+ public register ( ) : Service < R > | false {
3738 if ( Core . me === null ) {
3839 throw new Error (
3940 'Error: you are trying register `' +
@@ -46,21 +47,21 @@ export class Service extends ParentResourceService {
4647 this . cachestore = new CacheStore ( ) ;
4748 this . schema = { ...{ } , ...Base . Schema , ...this . schema } ;
4849
49- return Core . me . registerService ( this ) ;
50+ return Core . me . registerService < R > ( this ) ;
5051 }
5152
52- public newResource ( ) : Resource {
53- let resource : Resource = new Resource ( ) ;
53+ public newResource ( ) : R {
54+ let resource = new this . resource ( ) ;
5455
55- return resource ;
56+ return < R > resource ;
5657 }
5758
58- public new < T extends Resource > ( ) : T {
59+ public new ( ) : R {
5960 let resource = this . newResource ( ) ;
6061 resource . type = this . type ;
6162 resource . reset ( ) ;
6263
63- return < T > resource ;
64+ return resource ;
6465 }
6566
6667 public getPrePath ( ) : string {
@@ -70,13 +71,13 @@ export class Service extends ParentResourceService {
7071 return this . path ? this . path : this . type ;
7172 }
7273
73- public get < T extends Resource > (
74+ public get (
7475 id : string ,
7576 params ?: IParamsResource | Function ,
7677 fc_success ?: Function ,
7778 fc_error ?: Function
78- ) : T {
79- return < T > this . __exec ( {
79+ ) : R {
80+ return < R > this . __exec ( {
8081 id : id ,
8182 params : params ,
8283 fc_success : fc_success ,
@@ -114,7 +115,7 @@ export class Service extends ParentResourceService {
114115 } ) ;
115116 }
116117
117- protected __exec ( exec_params : IExecParams ) : Resource | ICollection | void {
118+ protected __exec ( exec_params : IExecParams ) : R | ICollection | void {
118119 let exec_pp = super . proccess_exec_params ( exec_params ) ;
119120
120121 switch ( exec_pp . exec_type ) {
@@ -146,7 +147,7 @@ export class Service extends ParentResourceService {
146147 params : IParamsResource ,
147148 fc_success ,
148149 fc_error
149- ) : Resource {
150+ ) : R {
150151 // http request
151152 let path = new PathBuilder ( ) ;
152153 path . applyParams ( this , params ) ;
@@ -175,7 +176,7 @@ export class Service extends ParentResourceService {
175176 }
176177 ) ;
177178
178- return resource ;
179+ return < R > resource ;
179180 } else if ( Core . injectedServices . rsJsonapiConfig . cachestore_support ) {
180181 // CACHESTORE
181182 this . getService ( )
@@ -199,7 +200,7 @@ export class Service extends ParentResourceService {
199200 this . getGetFromServer ( path , fc_success , fc_error , resource ) ;
200201 }
201202
202- return resource ;
203+ return < R > resource ;
203204 }
204205
205206 private getGetFromServer ( path , fc_success , fc_error , resource : Resource ) {
@@ -477,7 +478,7 @@ export class Service extends ParentResourceService {
477478 /*
478479 @return This resource like a service
479480 */
480- public getService < T extends Service > ( ) : T {
481+ public getService < T extends Service < R > > ( ) : T {
481482 return < T > ( Converter . getService ( this . type ) || this . register ( ) ) ;
482483 // let serv = Converter.getService(this.type);
483484 // if (serv) {
0 commit comments