From d9f864d75c77c2efde423dc7feda9258f4d3d9c9 Mon Sep 17 00:00:00 2001 From: jiko21 Date: Thu, 23 Oct 2025 22:49:34 +0900 Subject: [PATCH 1/5] fix: bug --- src/tsUtil.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/tsUtil.ts b/src/tsUtil.ts index b1a59d1..6163556 100644 --- a/src/tsUtil.ts +++ b/src/tsUtil.ts @@ -15,7 +15,6 @@ export function traverseNode(node: ts.Node, indent: number = 0): HtmlJson { ts.isIdentifierOrThisTypeNode(member.name) && ts.isPropertySignature(member) ) { - console.log(member.name.escapedText); if ( member.type && ts.isLiteralTypeNode(member.type) && @@ -65,9 +64,9 @@ export function visit(node: ts.Node, checker: ts.TypeChecker, outPath: string) { ) { try { const type = checker.getTypeAtLocation(node); - const stringJSON = checker.typeToTypeNode(type, undefined, undefined); + const stringJSON = checker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.InTypeAlias | ts.NodeBuilderFlags.NoTruncation); if (stringJSON) { - const result = traverseNode(stringJSON); + const result = traverseNode(stringJSON, 0); const writeStream = createWriteStream(outPath, { flags: 'w' }); renderToStream(result, writeStream); writeStream.end('\n'); From d7a54ae61bf8f275dcff3de207452c92a135ed0c Mon Sep 17 00:00:00 2001 From: jiko21 Date: Thu, 23 Oct 2025 22:49:46 +0900 Subject: [PATCH 2/5] fix: branded --- src/html.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/html.ts b/src/html.ts index 03fed42..b585018 100644 --- a/src/html.ts +++ b/src/html.ts @@ -50,7 +50,7 @@ type InvalidDivContent = { __invalidType: T; }; -declare const pBrand: unique symbol; +declare const divBrand: unique symbol; export type Div = T extends Html ? InvalidDivContent @@ -58,10 +58,12 @@ export type Div = T extends Html : T extends HTMLElement[] ? { + [divBrand]: 'div'; children: T; } : T extends HTMLElement ? { + [divBrand]: 'div'; children: T; } : never; @@ -71,6 +73,8 @@ type InvalidPContent = { __invalidType: T; }; +declare const pBrand: unique symbol; + export type P = T extends Div ? InvalidPContent : T extends Html From d4827c97748b15c00ee1e3a81e20eb815aea01a6 Mon Sep 17 00:00:00 2001 From: jiko21 Date: Thu, 23 Oct 2025 22:50:21 +0900 Subject: [PATCH 3/5] update: sample --- examples/html.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/html.ts b/examples/html.ts index 2e81765..e98088a 100644 --- a/examples/html.ts +++ b/examples/html.ts @@ -1,4 +1,4 @@ -import type { Html, P } from '../src/html'; +import type { Html, P, Body, Div } from '../src/html'; // type A = HTML<"aaaa">; // type B = Html< @@ -11,6 +11,14 @@ import type { Html, P } from '../src/html'; /** * entrypoint */ -type B = Html<[P<'Hello World'>, P<'This is test'>]>; +// type B = Html<[P<'Hello World'>, P<'This is test'>]>; // type B = Html>; -// type B = Html, P<"This is test">]>>>; +type ComplexHtml = Html< + Body< + [ + Div<[P<'First paragraph'>, P<'Second paragraph'>]>, + P<'test'>, + Div<[P<'test1'>, Div>]>, + ] + > +>; From 249c66b04e88e2e7d732b108301779426c1fce6c Mon Sep 17 00:00:00 2001 From: jiko21 Date: Thu, 23 Oct 2025 23:04:52 +0900 Subject: [PATCH 4/5] fix: format --- examples/html.ts | 2 +- src/tsUtil.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/html.ts b/examples/html.ts index e98088a..26c27ee 100644 --- a/examples/html.ts +++ b/examples/html.ts @@ -19,6 +19,6 @@ type ComplexHtml = Html< Div<[P<'First paragraph'>, P<'Second paragraph'>]>, P<'test'>, Div<[P<'test1'>, Div>]>, - ] + ] > >; diff --git a/src/tsUtil.ts b/src/tsUtil.ts index 6163556..dae9529 100644 --- a/src/tsUtil.ts +++ b/src/tsUtil.ts @@ -64,7 +64,11 @@ export function visit(node: ts.Node, checker: ts.TypeChecker, outPath: string) { ) { try { const type = checker.getTypeAtLocation(node); - const stringJSON = checker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.InTypeAlias | ts.NodeBuilderFlags.NoTruncation); + const stringJSON = checker.typeToTypeNode( + type, + undefined, + ts.NodeBuilderFlags.InTypeAlias | ts.NodeBuilderFlags.NoTruncation + ); if (stringJSON) { const result = traverseNode(stringJSON, 0); const writeStream = createWriteStream(outPath, { flags: 'w' }); From 6fa0d20a6f285e504d5966f33855771be02b27b2 Mon Sep 17 00:00:00 2001 From: jiko21 Date: Thu, 23 Oct 2025 23:07:37 +0900 Subject: [PATCH 5/5] fix: obey lint --- examples/html.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/html.ts b/examples/html.ts index 26c27ee..519fbd3 100644 --- a/examples/html.ts +++ b/examples/html.ts @@ -1,4 +1,4 @@ -import type { Html, P, Body, Div } from '../src/html'; +import type { Body, Div, Html, P } from '../src/html'; // type A = HTML<"aaaa">; // type B = Html<