From 1f6eb83d7e2694caaed45ba7a890a1fcbceb69d1 Mon Sep 17 00:00:00 2001 From: markw65 Date: Fri, 8 Sep 2023 18:28:35 -0700 Subject: [PATCH] Even more compile time checking --- test/types/peg.test-d.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/types/peg.test-d.ts b/test/types/peg.test-d.ts index 28b0563c..75eee18d 100644 --- a/test/types/peg.test-d.ts +++ b/test/types/peg.test-d.ts @@ -424,6 +424,17 @@ describe("peg.d.ts", () => { }, }); + // Extract the visitor object + type VisitorArg + = typeof visit extends peggy.compiler.visitor.Visitor + ? U : never; + + // Extract the functions that don't return `any` + type DefinedKeys = keyof { + [K in keyof VisitorArg as VisitorArg[K] extends (...args: any) => any + ? unknown extends ReturnType ? never : K : never]: true + }; + visit(grammar); const astKeys = [ @@ -450,12 +461,11 @@ describe("peg.d.ts", () => { "text", "top_level_initializer", "zero_or_more", - ] as const; + ] satisfies AstTypes[]; expect(Object.keys(visited).sort()).toStrictEqual(astKeys); - for (const key of astKeys) { - expectType(key); - } + expectType(astKeys); + expectType(astKeys); }); it("compiles", () => {