@drunkcod/argis 0.0.10 → 0.0.11

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.
@@ -32,10 +32,10 @@ export declare function assertNotNil<T>(x: T | null): asserts x is T;
32
32
  export declare function argNotNil<T, K extends keyof T>(x: T, key: K): asserts x is T & {
33
33
  [P in K]-?: NonNullable<T[K]>;
34
34
  };
35
- export declare function hasOwn<T extends object, K extends PropertyKey>(x: T, key: K): x is T & WithKey<K>;
36
- export declare function hasOwn<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
37
- export declare function hasKey<T extends object, K extends PropertyKey>(x: T, key: K): x is T & WithKey<K>;
38
- export declare function hasKey<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
35
+ export declare function hasOwn<T extends object, K extends PropertyKey>(x: T | unknown, key: K): x is T & WithKey<K>;
36
+ export declare function hasOwn<T extends object, K extends PropertyKey, V>(x: T | unknown, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
37
+ export declare function hasKey<T extends object, K extends PropertyKey>(x: T | unknown, key: K): x is T & WithKey<K>;
38
+ export declare function hasKey<T extends object, K extends PropertyKey, V>(x: T | unknown, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
39
39
  export declare function assertOwn<T extends object, K extends PropertyKey>(x: T, key: K): asserts x is T & WithKey<K>;
40
40
  export declare function assertOwn<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): asserts x is T & WithKey<K, V>;
41
41
  export declare function assertKey<T extends object, K extends PropertyKey>(x: T, key: K): asserts x is T & WithKey<K>;
package/lib/cjs/index.js CHANGED
@@ -49,7 +49,7 @@ function hasOwn(x, key, ofType) {
49
49
  return _hasOwn(x, key) && (ofType == undefined || ofType(x[key]));
50
50
  }
51
51
  function _hasKey(x, key) {
52
- return key in x;
52
+ return typeof x === 'object' && key in x;
53
53
  }
54
54
  function hasKey(x, key, ofType) {
55
55
  return _hasKey(x, key) && (ofType == undefined || ofType(x[key]));
package/lib/index.d.ts CHANGED
@@ -32,10 +32,10 @@ export declare function assertNotNil<T>(x: T | null): asserts x is T;
32
32
  export declare function argNotNil<T, K extends keyof T>(x: T, key: K): asserts x is T & {
33
33
  [P in K]-?: NonNullable<T[K]>;
34
34
  };
35
- export declare function hasOwn<T extends object, K extends PropertyKey>(x: T, key: K): x is T & WithKey<K>;
36
- export declare function hasOwn<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
37
- export declare function hasKey<T extends object, K extends PropertyKey>(x: T, key: K): x is T & WithKey<K>;
38
- export declare function hasKey<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
35
+ export declare function hasOwn<T extends object, K extends PropertyKey>(x: T | unknown, key: K): x is T & WithKey<K>;
36
+ export declare function hasOwn<T extends object, K extends PropertyKey, V>(x: T | unknown, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
37
+ export declare function hasKey<T extends object, K extends PropertyKey>(x: T | unknown, key: K): x is T & WithKey<K>;
38
+ export declare function hasKey<T extends object, K extends PropertyKey, V>(x: T | unknown, key: K, ofType: (found: unknown) => found is V): x is T & WithKey<K, V>;
39
39
  export declare function assertOwn<T extends object, K extends PropertyKey>(x: T, key: K): asserts x is T & WithKey<K>;
40
40
  export declare function assertOwn<T extends object, K extends PropertyKey, V>(x: T, key: K, ofType: (found: unknown) => found is V): asserts x is T & WithKey<K, V>;
41
41
  export declare function assertKey<T extends object, K extends PropertyKey>(x: T, key: K): asserts x is T & WithKey<K>;
package/lib/index.js CHANGED
@@ -33,7 +33,7 @@ export function hasOwn(x, key, ofType) {
33
33
  return _hasOwn(x, key) && (ofType == undefined || ofType(x[key]));
34
34
  }
35
35
  function _hasKey(x, key) {
36
- return key in x;
36
+ return typeof x === 'object' && key in x;
37
37
  }
38
38
  export function hasKey(x, key, ofType) {
39
39
  return _hasKey(x, key) && (ofType == undefined || ofType(x[key]));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@drunkcod/argis",
3
3
  "type": "module",
4
- "version": "0.0.10",
4
+ "version": "0.0.11",
5
5
  "description": "Tiny method arg checking with strong types.",
6
6
  "scripts": {
7
7
  "clean": "rimraf lib",