@shkumbinhsn/try-catch 0.0.2 → 0.0.3

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.
@@ -1,4 +1,5 @@
1
1
  const errorSymbol = Symbol();
2
+
2
3
  type ErrorSymbol = typeof errorSymbol;
3
4
 
4
5
  export type Throws<T extends Error> = {
@@ -7,7 +8,12 @@ export type Throws<T extends Error> = {
7
8
 
8
9
  type ExtractErrors<T> = T extends Throws<infer E> ? E : never;
9
10
 
10
- type DataError<T> = [T, null] | [null, Error | ExtractErrors<T>];
11
- type TryCatchReturn<T> = T extends Promise<infer R> ? Promise<DataError<R>> : DataError<T>;
11
+ type StripThrows<T> = T extends infer R & Throws<Error> ? R : T;
12
+
13
+ type DataError<T> = [StripThrows<T>, null] | [null, Error | ExtractErrors<T>];
14
+
15
+ type TryCatchReturn<T> = T extends Promise<infer R>
16
+ ? Promise<DataError<R>>
17
+ : DataError<T>;
12
18
 
13
- export declare function tryCatch<T>(fn: () => T): TryCatchReturn<T>;
19
+ export declare function tryCatch<T>(fn: () => T): TryCatchReturn<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shkumbinhsn/try-catch",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A utility package for handling try-catch blocks in TypeScript.",
5
5
  "main": "./lib/try-catch.js",
6
6
  "module": "./lib/try-catch.js",
@@ -22,11 +22,11 @@
22
22
  "access": "public"
23
23
  },
24
24
  "scripts": {
25
- "test": "echo \"No test specified\" && exit 0"
25
+ "test": "tsc -p tsconfig.json"
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
29
- "url": "https://github.com/shkumbinhasani/ts-try-catch"
29
+ "url": "git+https://github.com/shkumbinhasani/ts-try-catch.git"
30
30
  },
31
31
  "keywords": [
32
32
  "typescript",