rsult 1.0.1 → 1.0.2

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.
package/deno.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@int/rsult",
3
+ "version": "1.0.2",
4
+ "exports": "./src/lib.ts"
5
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "rsult",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "src/lib.ts",
6
6
  "repository": "https://github.com/indicium-ag/rsult",
7
7
  "keywords": [],
8
- "author": "",
9
- "license": "ISC",
8
+ "author": "Kenan Sulayman <kenan@sly.mn>",
9
+ "license": "MIT",
10
10
  "devDependencies": {
11
11
  "@swc/core": "^1.4.12",
12
12
  "@swc/jest": "^0.2.36",
package/src/lib.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './result';
2
- export * from './option';
1
+ export * from './result.ts';
2
+ export * from './option.ts';
package/src/option.ts CHANGED
@@ -1,4 +1,5 @@
1
- export type Option<T> = OptionSome<T> | OptionNone<T>;
1
+ export type Option<T> =
2
+ OptionSome<T> | OptionNone<T>;
2
3
 
3
4
  export interface IOptionCheck<T> {
4
5
  /**
@@ -178,7 +179,7 @@ export interface IOptionUtility<T> {
178
179
  * const myOption is None<number>();
179
180
  * const value = myOption.unwrap_or_default(); // 0
180
181
  */
181
- unwrap_or_default(): T;
182
+ unwrap_or_default(): T | null;
182
183
  }
183
184
 
184
185
  export interface IOptionMutate<T> {
@@ -280,7 +281,8 @@ export interface IOption<T> extends
280
281
 
281
282
  export class OptionSome<T> implements IOption<T> {
282
283
  readonly _tag = 'Some' as const;
283
- readonly _T!: T;
284
+ // @ts-ignore
285
+ readonly _T: T;
284
286
 
285
287
  constructor(readonly value: T) { }
286
288
 
@@ -352,7 +354,7 @@ export class OptionSome<T> implements IOption<T> {
352
354
  return this.value;
353
355
  }
354
356
 
355
- unwrap_or_default(): T {
357
+ unwrap_or_default(): T | null {
356
358
  return this.value;
357
359
  }
358
360
 
@@ -408,7 +410,8 @@ export class OptionSome<T> implements IOption<T> {
408
410
 
409
411
  export class OptionNone<T> implements IOption<T> {
410
412
  private readonly _tag: 'None' = 'None';
411
- private readonly _T!: T;
413
+ // @ts-ignore
414
+ private readonly _T: T;
412
415
 
413
416
  is_some(): this is never {
414
417
  return false;
@@ -470,7 +473,7 @@ export class OptionNone<T> implements IOption<T> {
470
473
  return fn();
471
474
  }
472
475
 
473
- unwrap_or_default() {
476
+ unwrap_or_default(): T | null {
474
477
  return null as any;
475
478
  }
476
479
 
@@ -499,11 +502,11 @@ export class OptionNone<T> implements IOption<T> {
499
502
  }
500
503
  }
501
504
 
502
- export const Some = <T>(val: T) => {
505
+ export const Some = <T>(val: T): Option<T> => {
503
506
  return new OptionSome<T>(val);
504
507
  };
505
508
 
506
- export const None = <T>() => {
509
+ export const None = <T>(): Option<T> => {
507
510
  return new OptionNone<T>();
508
511
  };
509
512
 
@@ -452,7 +452,7 @@ describe('Result', () => {
452
452
  const promise = Promise.reject(new Error(errorMsg));
453
453
  const result = await result_from_promise(promise);
454
454
  expect(result.is_err()).toBe(true);
455
- expect((await result.unwrap_err()).message).toBe(errorMsg);
455
+ expect(result.unwrap_err().message).toBe(errorMsg);
456
456
  });
457
457
  });
458
458
  });
package/src/result.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { Option, None, Some } from './option';
1
+ import { Option, None, Some } from './option.ts';
2
2
 
3
- export type Result<T, E> = ResultOk<T, E> | ResultErr<T, E>;
3
+ export type Result<T, E> =
4
+ ResultOk<T, E> | ResultErr<T, E>;
4
5
 
5
6
  export interface IResultCore<T, E> {
6
7
  /**
@@ -365,8 +366,10 @@ export const isResultErr = <T, E>(val: any): val is ResultErr<T, E> => {
365
366
 
366
367
  export class ResultOk<T, E> implements IResult<T, E> {
367
368
  private readonly _tag = 'Ok' as const;
368
- private readonly _T!: T;
369
- private readonly _E!: E;
369
+ // @ts-ignore
370
+ private readonly _T: T;
371
+ // @ts-ignore
372
+ private readonly _E: E;
370
373
 
371
374
  constructor(readonly value: T) {
372
375
  }
@@ -494,8 +497,10 @@ export class ResultOk<T, E> implements IResult<T, E> {
494
497
 
495
498
  export class ResultErr<T, E> implements IResult<T, E> {
496
499
  private readonly _tag: 'Err' = 'Err';
497
- private readonly _T!: T;
498
- private readonly _E!: E;
500
+ // @ts-ignore
501
+ private readonly _T: T;
502
+ // @ts-ignore
503
+ private readonly _E: E;
499
504
 
500
505
  constructor(readonly value: E) {
501
506
  }
@@ -613,12 +618,11 @@ export class ResultErr<T, E> implements IResult<T, E> {
613
618
  return this.value;
614
619
  }
615
620
  }
616
-
617
- export const Ok = <T, E>(val: T) => {
621
+ export const Ok = <T, E>(val: T): Result<T, never> => {
618
622
  return new ResultOk<T, E>(val) as Result<T, never>;
619
623
  };
620
624
 
621
- export const Err = <T, E>(val: E) => {
625
+ export const Err = <T, E>(val: E): Result<never, E> => {
622
626
  return new ResultErr<T, E>(val) as Result<never, E>;
623
627
  };
624
628
 
package/tsconfig.json CHANGED
@@ -10,6 +10,7 @@
10
10
  "allowJs": false,
11
11
  "moduleResolution": "node",
12
12
  "forceConsistentCasingInFileNames": true,
13
+ "allowImportingTsExtensions": true,
13
14
  "noImplicitReturns": true,
14
15
  "noImplicitThis": true,
15
16
  "noImplicitAny": true,