arktype 2.0.0-dev.0 → 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.
- package/__tests__/array.test.ts +270 -151
- package/__tests__/badDefinitionType.test.ts +10 -3
- package/__tests__/basis.test.ts +6 -2
- package/__tests__/bounds.test.ts +282 -352
- package/__tests__/cast.test.ts +7 -2
- package/__tests__/completions.test.ts +8 -3
- package/__tests__/config.test.ts +95 -167
- package/__tests__/dateLiteral.test.ts +8 -4
- package/__tests__/declared.test.ts +7 -6
- package/__tests__/discrimination.test.ts +1 -1
- package/__tests__/divisor.test.ts +46 -22
- package/__tests__/enclosed.test.ts +39 -25
- package/__tests__/examples.test.ts +56 -56
- package/__tests__/expressions.test.ts +184 -112
- package/__tests__/generic.test.ts +307 -288
- package/__tests__/group.test.ts +67 -54
- package/__tests__/imports.test.ts +62 -49
- package/__tests__/instanceof.test.ts +25 -23
- package/__tests__/intersection.test.ts +52 -48
- package/__tests__/keyTraversal.test.ts +77 -73
- package/__tests__/keyof.test.ts +68 -52
- package/__tests__/keywords.test.ts +164 -138
- package/__tests__/literal.test.ts +60 -21
- package/__tests__/match.bench.ts +31 -0
- package/__tests__/match.test.ts +222 -22
- package/__tests__/narrow.test.ts +52 -54
- package/__tests__/objectLiteral.test.ts +347 -205
- package/__tests__/operator.bench.ts +4 -4
- package/__tests__/pipe.test.ts +501 -0
- package/__tests__/realWorld.test.ts +63 -0
- package/__tests__/regex.test.ts +17 -7
- package/__tests__/scope.bench.ts +1 -1
- package/__tests__/scope.test.ts +257 -23
- package/__tests__/serialization.test.ts +19 -0
- package/__tests__/string.test.ts +11 -7
- package/__tests__/submodule.test.ts +26 -39
- package/__tests__/this.test.ts +83 -57
- package/__tests__/thunk.test.ts +13 -7
- package/__tests__/traverse.test.ts +76 -54
- package/__tests__/tsGenerics.test.ts +12 -12
- package/__tests__/type.test.ts +36 -0
- package/__tests__/typeReference.test.ts +7 -7
- package/__tests__/unenclosed.test.ts +116 -100
- package/__tests__/union.test.ts +171 -104
- package/ark.ts +21 -65
- package/generic.ts +69 -0
- package/main.ts +6 -18
- package/match.ts +195 -93
- package/module.ts +15 -0
- package/out/ark.d.ts +15 -39
- package/out/ark.js +9 -18
- package/out/ark.js.map +1 -1
- package/out/generic.d.ts +21 -0
- package/out/generic.js +24 -0
- package/out/generic.js.map +1 -0
- package/out/main.d.ts +6 -7
- package/out/main.js +4 -3
- package/out/main.js.map +1 -1
- package/out/match.d.ts +57 -34
- package/out/match.js +51 -17
- package/out/match.js.map +1 -1
- package/out/module.d.ts +10 -0
- package/out/module.js +3 -0
- package/out/module.js.map +1 -0
- package/out/parser/definition.d.ts +11 -13
- package/out/parser/definition.js +10 -13
- package/out/parser/definition.js.map +1 -1
- package/out/parser/generic.d.ts +5 -7
- package/out/parser/generic.js +7 -11
- package/out/parser/generic.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +45 -14
- package/out/parser/objectLiteral.js +61 -52
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/bounds.d.ts +10 -8
- package/out/parser/semantic/bounds.js +0 -1
- package/out/parser/semantic/bounds.js.map +1 -1
- package/out/parser/semantic/divisor.d.ts +5 -7
- package/out/parser/semantic/divisor.js +0 -1
- package/out/parser/semantic/infer.d.ts +24 -0
- package/out/parser/semantic/infer.js +1 -0
- package/out/parser/semantic/infer.js.map +1 -0
- package/out/parser/semantic/utils.d.ts +3 -7
- package/out/parser/semantic/utils.js +0 -1
- package/out/parser/semantic/validate.d.ts +15 -14
- package/out/parser/semantic/validate.js +1 -1
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -13
- package/out/parser/string/reduce/dynamic.js +31 -26
- package/out/parser/string/reduce/dynamic.js.map +1 -1
- package/out/parser/string/reduce/shared.d.ts +6 -20
- package/out/parser/string/reduce/shared.js +0 -1
- package/out/parser/string/reduce/shared.js.map +1 -1
- package/out/parser/string/reduce/static.d.ts +27 -24
- package/out/parser/string/reduce/static.js +0 -1
- package/out/parser/string/shift/operand/date.d.ts +3 -3
- package/out/parser/string/shift/operand/date.js +4 -7
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +4 -19
- package/out/parser/string/shift/operand/enclosed.js +12 -13
- package/out/parser/string/shift/operand/enclosed.js.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
- package/out/parser/string/shift/operand/genericArgs.js +6 -10
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
- package/out/parser/string/shift/operand/operand.d.ts +3 -4
- package/out/parser/string/shift/operand/operand.js +8 -12
- package/out/parser/string/shift/operand/operand.js.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +15 -22
- package/out/parser/string/shift/operand/unenclosed.js +24 -36
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts +9 -13
- package/out/parser/string/shift/operator/bounds.js +43 -54
- package/out/parser/string/shift/operator/bounds.js.map +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts +2 -4
- package/out/parser/string/shift/operator/divisor.js +1 -3
- package/out/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/operator/operator.d.ts +2 -3
- package/out/parser/string/shift/operator/operator.js +12 -19
- package/out/parser/string/shift/operator/operator.js.map +1 -1
- package/out/parser/string/shift/scanner.d.ts +2 -2
- package/out/parser/string/shift/scanner.js +14 -16
- package/out/parser/string/shift/scanner.js.map +1 -1
- package/out/parser/string/string.d.ts +8 -6
- package/out/parser/string/string.js +1 -3
- package/out/parser/string/string.js.map +1 -1
- package/out/parser/tuple.d.ts +102 -43
- package/out/parser/tuple.js +119 -87
- package/out/parser/tuple.js.map +1 -1
- package/out/scope.d.ts +43 -120
- package/out/scope.js +39 -209
- package/out/scope.js.map +1 -1
- package/out/type.d.ts +43 -64
- package/out/type.js +30 -131
- package/out/type.js.map +1 -1
- package/package.json +7 -3
- package/parser/definition.ts +77 -93
- package/parser/generic.ts +38 -40
- package/parser/objectLiteral.ts +172 -136
- package/parser/semantic/bounds.ts +33 -32
- package/parser/semantic/divisor.ts +8 -10
- package/parser/semantic/infer.ts +141 -0
- package/parser/semantic/utils.ts +12 -23
- package/parser/semantic/validate.ts +81 -73
- package/parser/string/reduce/dynamic.ts +67 -55
- package/parser/string/reduce/shared.ts +1 -3
- package/parser/string/reduce/static.ts +67 -69
- package/parser/string/shift/operand/date.ts +15 -14
- package/parser/string/shift/operand/enclosed.ts +30 -25
- package/parser/string/shift/operand/genericArgs.ts +46 -45
- package/parser/string/shift/operand/operand.ts +32 -38
- package/parser/string/shift/operand/unenclosed.ts +107 -158
- package/parser/string/shift/operator/bounds.ts +118 -112
- package/parser/string/shift/operator/divisor.ts +14 -17
- package/parser/string/shift/operator/operator.ts +35 -46
- package/parser/string/shift/scanner.ts +51 -50
- package/parser/string/string.ts +30 -35
- package/parser/tuple.ts +375 -307
- package/scope.ts +170 -453
- package/type.ts +193 -274
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/cyclic.test.ts +0 -144
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/morph.test.ts +0 -409
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/__tests__/typeMethods.test.ts +0 -69
- package/out/ark.d.ts.map +0 -1
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/main.d.ts.map +0 -1
- package/out/match.d.ts.map +0 -1
- package/out/parser/definition.d.ts.map +0 -1
- package/out/parser/generic.d.ts.map +0 -1
- package/out/parser/objectLiteral.d.ts.map +0 -1
- package/out/parser/semantic/bounds.d.ts.map +0 -1
- package/out/parser/semantic/divisor.d.ts.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js +0 -2
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -33
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/semantic/utils.d.ts.map +0 -1
- package/out/parser/semantic/validate.d.ts.map +0 -1
- package/out/parser/shared.d.ts +0 -54
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -47
- package/out/parser/shared.js.map +0 -1
- package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/out/parser/string/reduce/shared.d.ts.map +0 -1
- package/out/parser/string/reduce/static.d.ts.map +0 -1
- package/out/parser/string/shift/operand/date.d.ts.map +0 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
- package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/out/parser/string/shift/scanner.d.ts.map +0 -1
- package/out/parser/string/string.d.ts.map +0 -1
- package/out/parser/tuple.d.ts.map +0 -1
- package/out/scope.d.ts.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/out/type.d.ts.map +0 -1
- package/out/util.d.ts +0 -19
- package/out/util.d.ts.map +0 -1
- package/out/util.js +0 -7
- package/out/util.js.map +0 -1
- package/parser/semantic/intersections.ts +0 -46
- package/parser/semantic/semantic.ts +0 -144
- package/parser/shared.ts +0 -152
- package/util.ts +0 -36
|
@@ -1,73 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
+
// })
|
package/__tests__/keyof.test.ts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import { attest } from "@arktype/attest"
|
|
2
|
-
import {
|
|
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
|
-
|
|
6
|
+
contextualize(() => {
|
|
10
7
|
it("autocompletion", () => {
|
|
11
8
|
// @ts-expect-error
|
|
12
|
-
attest(() => type("k")).
|
|
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
|
-
|
|
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 =
|
|
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(
|
|
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"
|
|
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
|
-
"
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
})
|