@cashscript/utils 0.13.2 → 0.14.0-next.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.
package/dist/types.d.ts CHANGED
@@ -24,7 +24,8 @@ export declare enum PrimitiveType {
24
24
  PUBKEY = "pubkey",
25
25
  SIG = "sig",
26
26
  DATASIG = "datasig",
27
- ANY = "any"
27
+ ANY = "any",
28
+ VOID = "void"
28
29
  }
29
30
  export declare function explicitlyCastable(from?: Type, to?: Type): boolean;
30
31
  export declare function implicitlyCastable(actual?: Type, expected?: Type): boolean;
package/dist/types.js CHANGED
@@ -38,6 +38,7 @@ export var PrimitiveType;
38
38
  PrimitiveType["SIG"] = "sig";
39
39
  PrimitiveType["DATASIG"] = "datasig";
40
40
  PrimitiveType["ANY"] = "any";
41
+ PrimitiveType["VOID"] = "void";
41
42
  })(PrimitiveType || (PrimitiveType = {}));
42
43
  const ExplicitlyCastableTo = {
43
44
  [PrimitiveType.INT]: [PrimitiveType.INT, PrimitiveType.BOOL],
@@ -47,10 +48,14 @@ const ExplicitlyCastableTo = {
47
48
  [PrimitiveType.SIG]: [PrimitiveType.SIG],
48
49
  [PrimitiveType.DATASIG]: [PrimitiveType.DATASIG],
49
50
  [PrimitiveType.ANY]: [],
51
+ [PrimitiveType.VOID]: [],
50
52
  };
51
53
  export function explicitlyCastable(from, to) {
52
54
  if (!from || !to)
53
55
  return false;
56
+ // `void` is not a real value type, so it can never participate in a cast
57
+ if (from === PrimitiveType.VOID || to === PrimitiveType.VOID)
58
+ return false;
54
59
  // Tuples can't be cast
55
60
  if (from instanceof TupleType || to instanceof TupleType)
56
61
  return false;
@@ -104,6 +109,9 @@ export function explicitlyCastable(from, to) {
104
109
  export function implicitlyCastable(actual, expected) {
105
110
  if (!actual || !expected)
106
111
  return false;
112
+ // `void` is not a real value type, so it can never be assigned to or from (not even to `any`)
113
+ if (actual === PrimitiveType.VOID || expected === PrimitiveType.VOID)
114
+ return false;
107
115
  if (actual instanceof TupleType && expected instanceof TupleType) {
108
116
  const leftIsCompatible = implicitlyCastable(actual.leftType, expected.leftType);
109
117
  const rightIsCompatible = implicitlyCastable(actual.rightType, expected.rightType);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashscript/utils",
3
- "version": "0.13.2",
3
+ "version": "0.14.0-next.0",
4
4
  "description": "CashScript utilities and types",
5
5
  "keywords": [
6
6
  "bitcoin cash",
@@ -48,5 +48,5 @@
48
48
  "typescript": "^5.9.2",
49
49
  "vitest": "^4.0.15"
50
50
  },
51
- "gitHead": "a4f112abb0d035ecf018ebc694e2b081f25b3409"
51
+ "gitHead": "790d4a2c608ef492a9a1f886b1489d2e4ffe95e2"
52
52
  }