@labeg/tfetch 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,10 +17,12 @@ export interface TsRequestInit<T> extends Omit<RequestInit, "body"> {
17
17
  }
18
18
  export declare class TsFetch {
19
19
  protected readonly requestCache: Map<string, [PromiseResRej, PromiseResRej][]>;
20
+ /**
21
+ * Overloads
22
+ */
20
23
  send(options: TsRequestInit<void>): Promise<void>;
21
- send<T extends boolean>(options: TsRequestInit<T>): Promise<T>;
22
- send<T extends number>(options: TsRequestInit<T>): Promise<T>;
23
- send<T extends string>(options: TsRequestInit<T>): Promise<T>;
24
+ send<T extends (boolean | number | string)>(options: TsRequestInit<T>): Promise<T>;
25
+ send<T extends (boolean | number | string)[]>(options: TsRequestInit<T>): Promise<T>;
24
26
  send<T>(options: TsRequestInit<new () => T>): Promise<T>;
25
27
  send<T>(options: TsRequestInit<[new () => T]>): Promise<T[]>;
26
28
  protected handleError(response: Response): Promise<Response>;
@@ -93,7 +93,12 @@ export class TsFetch {
93
93
  else if (Array.isArray(returnType) &&
94
94
  responseText.startsWith("[")) {
95
95
  data = JSON.parse(responseText);
96
- // Return models.map((model: object) => new returnType[0]().fromJSON(model));
96
+ if ( // If its Serializable class
97
+ typeof returnType[0] === "function" &&
98
+ returnType[0].prototype instanceof Serializable) {
99
+ const constructor = returnType[0];
100
+ data = data.map((model) => new constructor().fromJSON(model));
101
+ }
97
102
  }
98
103
  else if (typeof returnType === "function" &&
99
104
  returnType.prototype instanceof Serializable &&
package/dist/index.d.ts CHANGED
@@ -6,9 +6,8 @@ declare const instance: TsFetch;
6
6
  export declare const tfetch: typeof instance.send;
7
7
  export declare const tf: {
8
8
  (options: import("./contructors/TsFetch.js").TsRequestInit<void>): Promise<void>;
9
- <T extends boolean>(options: import("./contructors/TsFetch.js").TsRequestInit<T>): Promise<T>;
10
- <T extends number>(options: import("./contructors/TsFetch.js").TsRequestInit<T>): Promise<T>;
11
- <T extends string>(options: import("./contructors/TsFetch.js").TsRequestInit<T>): Promise<T>;
9
+ <T extends (boolean | number | string)>(options: import("./contructors/TsFetch.js").TsRequestInit<T>): Promise<T>;
10
+ <T extends (boolean | number | string)[]>(options: import("./contructors/TsFetch.js").TsRequestInit<T>): Promise<T>;
12
11
  <T>(options: import("./contructors/TsFetch.js").TsRequestInit<new () => T>): Promise<T>;
13
12
  <T>(options: import("./contructors/TsFetch.js").TsRequestInit<[new () => T]>): Promise<T[]>;
14
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labeg/tfetch",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "author": "Eugene Labutin",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/LabEG/ts-fetch#readme",