arktype 2.0.0-dev.1 → 2.0.0-dev.10

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.
Files changed (219) hide show
  1. package/__tests__/array.test.ts +270 -151
  2. package/__tests__/badDefinitionType.test.ts +10 -3
  3. package/__tests__/basis.test.ts +6 -2
  4. package/__tests__/bounds.test.ts +282 -352
  5. package/__tests__/cast.test.ts +7 -2
  6. package/__tests__/completions.test.ts +8 -3
  7. package/__tests__/config.test.ts +95 -167
  8. package/__tests__/dateLiteral.test.ts +8 -4
  9. package/__tests__/declared.test.ts +7 -6
  10. package/__tests__/discrimination.test.ts +1 -1
  11. package/__tests__/divisor.test.ts +46 -22
  12. package/__tests__/enclosed.test.ts +39 -25
  13. package/__tests__/examples.test.ts +56 -56
  14. package/__tests__/expressions.test.ts +184 -112
  15. package/__tests__/generic.test.ts +307 -288
  16. package/__tests__/group.test.ts +67 -54
  17. package/__tests__/imports.test.ts +62 -49
  18. package/__tests__/instanceof.test.ts +25 -23
  19. package/__tests__/intersection.test.ts +52 -48
  20. package/__tests__/keyTraversal.test.ts +77 -73
  21. package/__tests__/keyof.test.ts +68 -52
  22. package/__tests__/keywords.test.ts +164 -138
  23. package/__tests__/literal.test.ts +60 -21
  24. package/__tests__/match.bench.ts +31 -0
  25. package/__tests__/match.test.ts +222 -22
  26. package/__tests__/narrow.test.ts +52 -54
  27. package/__tests__/objectLiteral.test.ts +347 -205
  28. package/__tests__/operator.bench.ts +4 -4
  29. package/__tests__/pipe.test.ts +501 -0
  30. package/__tests__/realWorld.test.ts +63 -0
  31. package/__tests__/regex.test.ts +17 -7
  32. package/__tests__/scope.bench.ts +1 -1
  33. package/__tests__/scope.test.ts +257 -23
  34. package/__tests__/serialization.test.ts +19 -0
  35. package/__tests__/string.test.ts +11 -7
  36. package/__tests__/submodule.test.ts +26 -39
  37. package/__tests__/this.test.ts +83 -57
  38. package/__tests__/thunk.test.ts +13 -7
  39. package/__tests__/traverse.test.ts +76 -54
  40. package/__tests__/tsGenerics.test.ts +12 -12
  41. package/__tests__/type.test.ts +36 -0
  42. package/__tests__/typeReference.test.ts +7 -7
  43. package/__tests__/unenclosed.test.ts +116 -100
  44. package/__tests__/union.test.ts +171 -104
  45. package/ark.ts +21 -65
  46. package/generic.ts +69 -0
  47. package/main.ts +6 -18
  48. package/match.ts +195 -93
  49. package/module.ts +15 -0
  50. package/out/ark.d.ts +15 -39
  51. package/out/ark.js +9 -18
  52. package/out/ark.js.map +1 -1
  53. package/out/generic.d.ts +21 -0
  54. package/out/generic.js +24 -0
  55. package/out/generic.js.map +1 -0
  56. package/out/main.d.ts +6 -7
  57. package/out/main.js +4 -3
  58. package/out/main.js.map +1 -1
  59. package/out/match.d.ts +57 -34
  60. package/out/match.js +51 -17
  61. package/out/match.js.map +1 -1
  62. package/out/module.d.ts +10 -0
  63. package/out/module.js +3 -0
  64. package/out/module.js.map +1 -0
  65. package/out/parser/definition.d.ts +11 -13
  66. package/out/parser/definition.js +10 -13
  67. package/out/parser/definition.js.map +1 -1
  68. package/out/parser/generic.d.ts +5 -7
  69. package/out/parser/generic.js +7 -11
  70. package/out/parser/generic.js.map +1 -1
  71. package/out/parser/objectLiteral.d.ts +45 -14
  72. package/out/parser/objectLiteral.js +61 -52
  73. package/out/parser/objectLiteral.js.map +1 -1
  74. package/out/parser/semantic/bounds.d.ts +10 -8
  75. package/out/parser/semantic/bounds.js +0 -1
  76. package/out/parser/semantic/bounds.js.map +1 -1
  77. package/out/parser/semantic/divisor.d.ts +5 -7
  78. package/out/parser/semantic/divisor.js +0 -1
  79. package/out/parser/semantic/infer.d.ts +24 -0
  80. package/out/parser/semantic/infer.js +1 -0
  81. package/out/parser/semantic/infer.js.map +1 -0
  82. package/out/parser/semantic/utils.d.ts +3 -7
  83. package/out/parser/semantic/utils.js +0 -1
  84. package/out/parser/semantic/validate.d.ts +15 -14
  85. package/out/parser/semantic/validate.js +1 -1
  86. package/out/parser/semantic/validate.js.map +1 -1
  87. package/out/parser/string/reduce/dynamic.d.ts +13 -13
  88. package/out/parser/string/reduce/dynamic.js +31 -26
  89. package/out/parser/string/reduce/dynamic.js.map +1 -1
  90. package/out/parser/string/reduce/shared.d.ts +6 -20
  91. package/out/parser/string/reduce/shared.js +0 -1
  92. package/out/parser/string/reduce/shared.js.map +1 -1
  93. package/out/parser/string/reduce/static.d.ts +27 -24
  94. package/out/parser/string/reduce/static.js +0 -1
  95. package/out/parser/string/shift/operand/date.d.ts +3 -3
  96. package/out/parser/string/shift/operand/date.js +4 -7
  97. package/out/parser/string/shift/operand/date.js.map +1 -1
  98. package/out/parser/string/shift/operand/enclosed.d.ts +4 -19
  99. package/out/parser/string/shift/operand/enclosed.js +12 -13
  100. package/out/parser/string/shift/operand/enclosed.js.map +1 -1
  101. package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
  102. package/out/parser/string/shift/operand/genericArgs.js +6 -10
  103. package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
  104. package/out/parser/string/shift/operand/operand.d.ts +3 -4
  105. package/out/parser/string/shift/operand/operand.js +8 -12
  106. package/out/parser/string/shift/operand/operand.js.map +1 -1
  107. package/out/parser/string/shift/operand/unenclosed.d.ts +15 -22
  108. package/out/parser/string/shift/operand/unenclosed.js +24 -36
  109. package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
  110. package/out/parser/string/shift/operator/bounds.d.ts +9 -13
  111. package/out/parser/string/shift/operator/bounds.js +43 -54
  112. package/out/parser/string/shift/operator/bounds.js.map +1 -1
  113. package/out/parser/string/shift/operator/divisor.d.ts +2 -4
  114. package/out/parser/string/shift/operator/divisor.js +1 -3
  115. package/out/parser/string/shift/operator/divisor.js.map +1 -1
  116. package/out/parser/string/shift/operator/operator.d.ts +2 -3
  117. package/out/parser/string/shift/operator/operator.js +12 -19
  118. package/out/parser/string/shift/operator/operator.js.map +1 -1
  119. package/out/parser/string/shift/scanner.d.ts +2 -2
  120. package/out/parser/string/shift/scanner.js +14 -16
  121. package/out/parser/string/shift/scanner.js.map +1 -1
  122. package/out/parser/string/string.d.ts +8 -6
  123. package/out/parser/string/string.js +1 -3
  124. package/out/parser/string/string.js.map +1 -1
  125. package/out/parser/tuple.d.ts +102 -43
  126. package/out/parser/tuple.js +119 -87
  127. package/out/parser/tuple.js.map +1 -1
  128. package/out/scope.d.ts +43 -120
  129. package/out/scope.js +39 -209
  130. package/out/scope.js.map +1 -1
  131. package/out/type.d.ts +43 -64
  132. package/out/type.js +30 -131
  133. package/out/type.js.map +1 -1
  134. package/package.json +7 -3
  135. package/parser/definition.ts +77 -93
  136. package/parser/generic.ts +38 -40
  137. package/parser/objectLiteral.ts +172 -136
  138. package/parser/semantic/bounds.ts +33 -32
  139. package/parser/semantic/divisor.ts +8 -10
  140. package/parser/semantic/infer.ts +141 -0
  141. package/parser/semantic/utils.ts +12 -23
  142. package/parser/semantic/validate.ts +81 -73
  143. package/parser/string/reduce/dynamic.ts +67 -55
  144. package/parser/string/reduce/shared.ts +1 -3
  145. package/parser/string/reduce/static.ts +67 -69
  146. package/parser/string/shift/operand/date.ts +15 -14
  147. package/parser/string/shift/operand/enclosed.ts +30 -25
  148. package/parser/string/shift/operand/genericArgs.ts +46 -45
  149. package/parser/string/shift/operand/operand.ts +32 -38
  150. package/parser/string/shift/operand/unenclosed.ts +107 -158
  151. package/parser/string/shift/operator/bounds.ts +118 -112
  152. package/parser/string/shift/operator/divisor.ts +14 -17
  153. package/parser/string/shift/operator/operator.ts +35 -46
  154. package/parser/string/shift/scanner.ts +51 -50
  155. package/parser/string/string.ts +30 -35
  156. package/parser/tuple.ts +375 -307
  157. package/scope.ts +170 -453
  158. package/type.ts +193 -274
  159. package/__tests__/astUtils.test.ts +0 -17
  160. package/__tests__/cyclic.test.ts +0 -144
  161. package/__tests__/jsdoc.test.ts +0 -64
  162. package/__tests__/morph.test.ts +0 -409
  163. package/__tests__/nodeDefinitions.test.ts +0 -190
  164. package/__tests__/typeMethods.test.ts +0 -69
  165. package/out/ark.d.ts.map +0 -1
  166. package/out/arkConfig.d.ts +0 -2
  167. package/out/arkConfig.d.ts.map +0 -1
  168. package/out/arkConfig.js +0 -10
  169. package/out/arkConfig.js.map +0 -1
  170. package/out/main.d.ts.map +0 -1
  171. package/out/match.d.ts.map +0 -1
  172. package/out/parser/definition.d.ts.map +0 -1
  173. package/out/parser/generic.d.ts.map +0 -1
  174. package/out/parser/objectLiteral.d.ts.map +0 -1
  175. package/out/parser/semantic/bounds.d.ts.map +0 -1
  176. package/out/parser/semantic/divisor.d.ts.map +0 -1
  177. package/out/parser/semantic/intersections.d.ts +0 -14
  178. package/out/parser/semantic/intersections.d.ts.map +0 -1
  179. package/out/parser/semantic/intersections.js +0 -2
  180. package/out/parser/semantic/intersections.js.map +0 -1
  181. package/out/parser/semantic/semantic.d.ts +0 -33
  182. package/out/parser/semantic/semantic.d.ts.map +0 -1
  183. package/out/parser/semantic/semantic.js +0 -2
  184. package/out/parser/semantic/semantic.js.map +0 -1
  185. package/out/parser/semantic/utils.d.ts.map +0 -1
  186. package/out/parser/semantic/validate.d.ts.map +0 -1
  187. package/out/parser/shared.d.ts +0 -54
  188. package/out/parser/shared.d.ts.map +0 -1
  189. package/out/parser/shared.js +0 -47
  190. package/out/parser/shared.js.map +0 -1
  191. package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
  192. package/out/parser/string/reduce/shared.d.ts.map +0 -1
  193. package/out/parser/string/reduce/static.d.ts.map +0 -1
  194. package/out/parser/string/shift/operand/date.d.ts.map +0 -1
  195. package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
  196. package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
  197. package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
  198. package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
  199. package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
  200. package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
  201. package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
  202. package/out/parser/string/shift/scanner.d.ts.map +0 -1
  203. package/out/parser/string/string.d.ts.map +0 -1
  204. package/out/parser/tuple.d.ts.map +0 -1
  205. package/out/scope.d.ts.map +0 -1
  206. package/out/test.d.ts +0 -2
  207. package/out/test.d.ts.map +0 -1
  208. package/out/test.js +0 -7
  209. package/out/test.js.map +0 -1
  210. package/out/tsconfig.build.tsbuildinfo +0 -1
  211. package/out/type.d.ts.map +0 -1
  212. package/out/util.d.ts +0 -19
  213. package/out/util.d.ts.map +0 -1
  214. package/out/util.js +0 -7
  215. package/out/util.js.map +0 -1
  216. package/parser/semantic/intersections.ts +0 -46
  217. package/parser/semantic/semantic.ts +0 -144
  218. package/parser/shared.ts +0 -152
  219. package/util.ts +0 -36
@@ -1,73 +1,77 @@
1
- import { attest } from "@arktype/attest"
2
- import { type } from "arktype"
3
-
4
- describe("key traversal", () => {
5
- const getExtraneousB = () => ({ a: "ok", b: "why?" })
6
- it("loose by default", () => {
7
- const t = type({
8
- a: "string"
9
- })
10
- const dataWithExtraneousB = getExtraneousB()
11
- attest(t(dataWithExtraneousB).out).equals(dataWithExtraneousB)
12
- })
13
- it("invalid union", () => {
14
- const o = type([{ a: "string" }, "|", { b: "boolean" }]).configure({
15
- keys: "strict"
16
- })
17
- attest(o({ a: 2 }).errors?.summary).snap(
18
- 'a must be a string or removed (was {"a":2})'
19
- )
20
- })
21
- it("distilled type", () => {
22
- const t = type({
23
- a: "string"
24
- }).configure({ keys: "distilled" })
25
- attest(t({ a: "ok" }).out).equals({ a: "ok" })
26
- attest(t(getExtraneousB()).out).snap({ a: "ok" })
27
- })
28
- it("distilled array", () => {
29
- const o = type({ a: "email[]" }).configure({
30
- keys: "distilled"
31
- })
32
- attest(o({ a: ["shawn@arktype.io"] }).out).snap({
33
- a: ["shawn@arktype.io"]
34
- })
35
- attest(o({ a: ["notAnEmail"] }).errors?.summary).snap(
36
- "a/0 must be a valid email (was 'notAnEmail')"
37
- )
38
- // can handle missing keys
39
- attest(o({ b: ["shawn"] }).errors?.summary).snap("a must be defined")
40
- })
41
- it("distilled union", () => {
42
- const o = type([{ a: "string" }, "|", { b: "boolean" }]).configure({
43
- keys: "distilled"
44
- })
45
- // can distill to first branch
46
- attest(o({ a: "to", z: "bra" }).out).snap({ a: "to" })
47
- // can distill to second branch
48
- attest(o({ b: true, c: false }).out).snap({ b: true })
49
- // can handle missing keys
50
- attest(o({ a: 2 }).errors?.summary).snap(
51
- 'a must be a string or b must be defined (was {"a":2})'
52
- )
53
- })
54
- it("strict type", () => {
55
- const t = type({
56
- a: "string"
57
- }).configure({ keys: "strict" })
58
- attest(t({ a: "ok" }).out).equals({ a: "ok" })
59
- attest(t(getExtraneousB()).errors?.summary).snap("b must be removed")
60
- })
61
- it("strict array", () => {
62
- const o = type({ a: "string[]" }).configure({
63
- keys: "strict"
64
- })
65
- attest(o({ a: ["shawn"] }).out).snap({ a: ["shawn"] })
66
- attest(o({ a: [2] }).errors?.summary).snap(
67
- "a/0 must be a string (was number)"
68
- )
69
- attest(o({ b: ["shawn"] }).errors?.summary).snap(
70
- "b must be removed\na must be defined"
71
- )
72
- })
73
- })
1
+ // TODO: reenable
2
+ // describe("key traversal", () => {
3
+ // const getExtraneousB = () => ({ a: "ok", b: "why?" })
4
+ // it("loose by default", () => {
5
+ // const t = type({
6
+ // a: "string"
7
+ // })
8
+ // const dataWithExtraneousB = getExtraneousB()
9
+ // attest(t(dataWithExtraneousB)).equals(dataWithExtraneousB)
10
+ // })
11
+ //
12
+ // it("invalid union", () => {
13
+ // const o = type([{ a: "string" }, "|", { b: "boolean" }]).configure({
14
+ // keys: "strict"
15
+ // })
16
+ // attest(o({ a: 2 }).toString()).snap(
17
+ // 'a must be a string or removed (was {"a":2})'
18
+ // )
19
+ // })
20
+ //
21
+ // it("distilled type", () => {
22
+ // const t = type({
23
+ // a: "string"
24
+ // }).configure({ keys: "distilled" })
25
+ // attest(t({ a: "ok" })).equals({ a: "ok" })
26
+ // attest(t(getExtraneousB())).snap({ a: "ok" })
27
+ // })
28
+ //
29
+ // it("distilled array", () => {
30
+ // const o = type({ a: "email[]" }).configure({
31
+ // keys: "distilled"
32
+ // })
33
+ // attest(o({ a: ["shawn@arktype.io"] })).snap({
34
+ // a: ["shawn@arktype.io"]
35
+ // })
36
+ // attest(o({ a: ["notAnEmail"] }).toString()).snap(
37
+ // "a/0 must be a valid email (was 'notAnEmail')"
38
+ // )
39
+ // // can handle missing keys
40
+ // attest(o({ b: ["shawn"] }).toString()).snap("a must be defined")
41
+ // })
42
+ //
43
+ // it("distilled union", () => {
44
+ // const o = type([{ a: "string" }, "|", { b: "boolean" }]).configure({
45
+ // keys: "distilled"
46
+ // })
47
+ // // can distill to first branch
48
+ // attest(o({ a: "to", z: "bra" })).snap({ a: "to" })
49
+ // // can distill to second branch
50
+ // attest(o({ b: true, c: false })).snap({ b: true })
51
+ // // can handle missing keys
52
+ // attest(o({ a: 2 }).toString()).snap(
53
+ // 'a must be a string or b must be defined (was {"a":2})'
54
+ // )
55
+ // })
56
+ //
57
+ // it("strict type", () => {
58
+ // const t = type({
59
+ // a: "string"
60
+ // }).configure({ keys: "strict" })
61
+ // attest(t({ a: "ok" })).equals({ a: "ok" })
62
+ // attest(t(getExtraneousB()).toString()).snap("b must be removed")
63
+ // })
64
+ //
65
+ // it("strict array", () => {
66
+ // const o = type({ a: "string[]" }).configure({
67
+ // keys: "strict"
68
+ // })
69
+ // attest(o({ a: ["shawn"] })).snap({ a: ["shawn"] })
70
+ // attest(o({ a: [2] }).toString()).snap(
71
+ // "a/0 must be a string (was number)"
72
+ // )
73
+ // attest(o({ b: ["shawn"] }).toString()).snap(
74
+ // "b must be removed\na must be defined"
75
+ // )
76
+ // })
77
+ // })
@@ -1,25 +1,26 @@
1
- import { attest } from "@arktype/attest"
2
- import { schema } from "@arktype/schema"
1
+ import { attest, contextualize } from "@arktype/attest"
2
+ import { rawSchema, writeUnresolvableMessage } from "@arktype/schema"
3
3
  import { type } from "arktype"
4
- import {
5
- writeMissingRightOperandMessage,
6
- writeUnresolvableMessage
7
- } from "../parser/string/shift/operand/unenclosed.js"
4
+ import { writeMissingRightOperandMessage } from "../parser/string/shift/operand/unenclosed.js"
8
5
 
9
- describe("keyof", () => {
6
+ contextualize(() => {
10
7
  it("autocompletion", () => {
11
8
  // @ts-expect-error
12
- attest(() => type("k")).type.errors("keyof ")
9
+ attest(() => type("k")).completions({ k: ["keyof"] })
13
10
  })
11
+
14
12
  it("root expression", () => {
15
13
  const t = type("keyof", "Date")
16
14
  attest<keyof Date>(t.infer)
17
- attest(t.json).equals(schema(Date).keyof().json)
15
+ const expected = rawSchema(Date).keyof()
16
+ attest(t.json).equals(expected.json)
18
17
  })
18
+
19
19
  it("primitive", () => {
20
20
  const t = type("keyof bigint")
21
21
  attest<keyof bigint>(t.infer)
22
- const expected = schema.units(
22
+ const expected = type(
23
+ "===",
23
24
  "toLocaleString",
24
25
  "toString",
25
26
  "valueOf",
@@ -27,11 +28,13 @@ describe("keyof", () => {
27
28
  )
28
29
  attest(t.json).equals(expected.json)
29
30
  })
31
+
30
32
  it("object literal", () => {
31
33
  const t = type({ a: "123", b: "123" }).keyof()
32
34
  attest<"a" | "b">(t.infer)
33
35
  attest(t.json).equals(type("'a'|'b'").json)
34
36
  })
37
+
35
38
  it("overlapping union", () => {
36
39
  const t = type({ a: "number", b: "boolean" })
37
40
  .or({ b: "number", c: "string" })
@@ -39,43 +42,52 @@ describe("keyof", () => {
39
42
  attest<"b">(t.infer)
40
43
  attest(t.json).equals(type("'b'").json)
41
44
  })
45
+
42
46
  it("non-overlapping union", () => {
43
47
  attest(() => type({ a: "number" }).or({ b: "number" }).keyof()).throws(
44
48
  'Intersection of "a" and "b" results in an unsatisfiable type'
45
49
  )
46
50
  })
51
+
47
52
  it("tuple expression", () => {
48
53
  const t = type(["keyof", { a: "string" }])
49
54
  attest<"a">(t.infer)
50
- attest(t.json).equals(schema.units("a").json)
55
+ attest(t.json).equals(type("'a'").json)
51
56
  })
57
+
52
58
  it("union including non-object", () => {
53
- attest(() => type({ a: "number" }).or("boolean").keyof()).throws(
54
- 'Intersection of "toString" or "valueOf" and "a" results in an unsatisfiable type'
59
+ attest(() => type({ a: "number" }).or("boolean").keyof()).throws.snap(
60
+ 'ParseError: Intersection of "toString" | "valueOf" and "a" results in an unsatisfiable type'
55
61
  )
56
62
  })
63
+
57
64
  it("unsatisfiable", () => {
58
- attest(() => type("keyof undefined")).throws(
59
- "Intersection of unknown and never results in an unsatisfiable type"
65
+ attest(() => type("keyof undefined")).throws.snap(
66
+ "ParseError: keyof undefined results in an unsatisfiable type"
60
67
  )
61
68
  })
69
+
62
70
  it("multiple keyofs", () => {
63
71
  const t = type("keyof keyof string")
64
72
  attest<"toString" | "valueOf">(t.infer)
65
- attest(t.json).equals(schema.units("toString", "valueOf").json)
73
+ attest(t.json).equals(type("===", "toString", "valueOf").json)
66
74
  })
75
+
67
76
  it("groupable", () => {
68
77
  const t = type("(keyof symbol & string)[]")
69
78
  attest<("toString" | "valueOf" | "description")[]>(t.infer)
70
79
  attest(t.json).equals(
71
- schema.units("toString", "valueOf", "description").array().json
80
+ type("===", "toString", "valueOf", "description").array().json
72
81
  )
73
82
  })
83
+
74
84
  it("intersection precedence", () => {
75
85
  const t = type("keyof symbol & symbol")
76
86
  attest<typeof Symbol.toStringTag | typeof Symbol.toPrimitive>(t.infer)
77
- attest(t.json).is(schema.units(Symbol.toStringTag, Symbol.toPrimitive).json)
87
+ // should be reference equal as it should just re-use the cached node
88
+ attest(t.json).is(type("===", Symbol.toStringTag, Symbol.toPrimitive).json)
78
89
  })
90
+
79
91
  it("union precedence", () => {
80
92
  const t = type("keyof boolean | number")
81
93
  attest<"valueOf" | number>(t.infer)
@@ -83,6 +95,7 @@ describe("keyof", () => {
83
95
  // given it is included in keyof string, it seems like an anomaly, but we include it
84
96
  attest(t.json).equals(type("number | 'valueOf' | 'toString'").json)
85
97
  })
98
+
86
99
  it("missing operand", () => {
87
100
  // @ts-expect-error
88
101
  attest(() => type("keyof "))
@@ -90,6 +103,7 @@ describe("keyof", () => {
90
103
  // it tries to autocomplete, so this is just a possible completion that would be included
91
104
  .type.errors("keyof bigint")
92
105
  })
106
+
93
107
  it("invalid operand", () => {
94
108
  // @ts-expect-error
95
109
  attest(() => type("keyof nope")).throwsAndHasTypeError(
@@ -97,38 +111,40 @@ describe("keyof", () => {
97
111
  )
98
112
  })
99
113
  // TODO: numeric
100
- it("array", () => {
101
- const t = type("keyof string[]")
102
- attest<keyof string[]>(t.infer)
103
- // the array prototype has many items and they vary based on the JS
104
- // flavor we're running in, so just check that the indices from the type
105
- // and one prototype key are present as a heuristic
106
- t.assert("0")
107
- t.assert("354")
108
- t.assert("map")
109
- t.assert(Symbol.iterator)
110
- attest(() => t.assert("0.1")).throws.snap(
111
- 'TypeError: / must be a string matching /^(?:0|(?:[1-9]\\d*))$/, "length", "at", "concat", "copyWithin", "fill", "find", "findIndex", "lastIndexOf", "pop", "push", "reverse", "shift", "unshift", "slice", "sort", "splice", "includes", "indexOf", "join", "keys", "entries", "values", "forEach", "filter", "flat", "flatMap", "map", "every", "some", "reduce", "reduceRight", "toLocaleString", "toString", "findLast", "findLastIndex", (symbol Symbol.iterator) or (symbol Symbol.unscopables) (was "0.1")'
112
- )
113
- attest(() => t.assert("-1")).throws.snap(
114
- 'TypeError: / must be a string matching /^(?:0|(?:[1-9]\\d*))$/, "length", "at", "concat", "copyWithin", "fill", "find", "findIndex", "lastIndexOf", "pop", "push", "reverse", "shift", "unshift", "slice", "sort", "splice", "includes", "indexOf", "join", "keys", "entries", "values", "forEach", "filter", "flat", "flatMap", "map", "every", "some", "reduce", "reduceRight", "toLocaleString", "toString", "findLast", "findLastIndex", (symbol Symbol.iterator) or (symbol Symbol.unscopables) (was "-1")'
115
- )
116
- })
117
- it("tuple", () => {
118
- const t = type(["keyof", ["string", "number"]])
119
- attest<keyof [string, number]>(t.infer)
120
- t.assert("1")
121
- t.assert("map")
122
- attest(() => t.assert("2")).throws.snap(
123
- 'TypeError: / must be "length", "0", "1", "at", "concat", "copyWithin", "fill", "find", "findIndex", "lastIndexOf", "pop", "push", "reverse", "shift", "unshift", "slice", "sort", "splice", "includes", "indexOf", "join", "keys", "entries", "values", "forEach", "filter", "flat", "flatMap", "map", "every", "some", "reduce", "reduceRight", "toLocaleString", "toString", "findLast", "findLastIndex", (symbol Symbol.iterator) or (symbol Symbol.unscopables) (was "2")'
124
- )
125
- })
126
- it("wellFormedNonNegativeInteger intersection", () => {
127
- const a = type([{ "1": "'foo'" }, "&", "string[]"])
128
- const t = type("keyof", a)
129
- // TODO should still include wellFormed
130
- attest(t.root.toString()).snap(
131
- '"1" or "at" or "concat" or "copyWithin" or "entries" or "every" or "fill" or "filter" or "find" or "findIndex" or "findLast" or "findLastIndex" or "flat" or "flatMap" or "forEach" or "includes" or "indexOf" or "join" or "keys" or "lastIndexOf" or "length" or "map" or "pop" or "push" or "reduce" or "reduceRight" or "reverse" or "shift" or "slice" or "some" or "sort" or "splice" or "toLocaleString" or "toString" or "unshift" or "values" or (symbol Symbol.iterator) or (symbol Symbol.unscopables) or /^(?:0|(?:[1-9]\\d*))$/'
132
- )
133
- })
114
+ // it("array", () => {
115
+ // const t = type("keyof string[]")
116
+ // attest<keyof string[]>(t.infer)
117
+ // // the array prototype has many items and they vary based on the JS
118
+ // // flavor we're running in, so just check that the indices from the type
119
+ // // and one prototype key are present as a heuristic
120
+ // t.assert("0")
121
+ // t.assert("354")
122
+ // t.assert("map")
123
+ // t.assert(Symbol.iterator)
124
+ // attest(() => t.assert("0.1")).throws.snap(
125
+ // 'TypeError: / must be a string matching /^(?:0|(?:[1-9]\\d*))$/, "length", "at", "concat", "copyWithin", "fill", "find", "findIndex", "lastIndexOf", "pop", "push", "reverse", "shift", "unshift", "slice", "sort", "splice", "includes", "indexOf", "join", "keys", "entries", "values", "forEach", "filter", "flat", "flatMap", "map", "every", "some", "reduce", "reduceRight", "toLocaleString", "toString", "findLast", "findLastIndex", (symbol Symbol.iterator) or (symbol Symbol.unscopables) (was "0.1")'
126
+ // )
127
+ // attest(() => t.assert("-1")).throws.snap(
128
+ // 'TypeError: / must be a string matching /^(?:0|(?:[1-9]\\d*))$/, "length", "at", "concat", "copyWithin", "fill", "find", "findIndex", "lastIndexOf", "pop", "push", "reverse", "shift", "unshift", "slice", "sort", "splice", "includes", "indexOf", "join", "keys", "entries", "values", "forEach", "filter", "flat", "flatMap", "map", "every", "some", "reduce", "reduceRight", "toLocaleString", "toString", "findLast", "findLastIndex", (symbol Symbol.iterator) or (symbol Symbol.unscopables) (was "-1")'
129
+ // )
130
+ // })
131
+
132
+ // it("tuple", () => {
133
+ // const t = type(["keyof", ["string", "number"]])
134
+ // attest<keyof [string, number]>(t.infer)
135
+ // t.assert("1")
136
+ // t.assert("map")
137
+ // attest(() => t.assert("2")).throws.snap(
138
+ // 'TypeError: / must be "length", "0", "1", "at", "concat", "copyWithin", "fill", "find", "findIndex", "lastIndexOf", "pop", "push", "reverse", "shift", "unshift", "slice", "sort", "splice", "includes", "indexOf", "join", "keys", "entries", "values", "forEach", "filter", "flat", "flatMap", "map", "every", "some", "reduce", "reduceRight", "toLocaleString", "toString", "findLast", "findLastIndex", (symbol Symbol.iterator) or (symbol Symbol.unscopables) (was "2")'
139
+ // )
140
+ // })
141
+
142
+ // it("wellFormedNonNegativeInteger intersection", () => {
143
+ // const a = type([{ "1": "'foo'" }, "&", "string[]"])
144
+ // const t = type("keyof", a)
145
+ // // TODO should still include wellFormed
146
+ // attest(t.toString()).snap(
147
+ // '"1" or "at" or "concat" or "copyWithin" or "entries" or "every" or "fill" or "filter" or "find" or "findIndex" or "findLast" or "findLastIndex" or "flat" or "flatMap" or "forEach" or "includes" or "indexOf" or "join" or "keys" or "lastIndexOf" or "length" or "map" or "pop" or "push" or "reduce" or "reduceRight" or "reverse" or "shift" or "slice" or "some" or "sort" or "splice" or "toLocaleString" or "toString" or "unshift" or "values" or (symbol Symbol.iterator) or (symbol Symbol.unscopables) or /^(?:0|(?:[1-9]\\d*))$/'
148
+ // )
149
+ // })
134
150
  })