Skip to content
This repository has been archived by the owner on Oct 9, 2021. It is now read-only.

Commit

Permalink
feat: Enable type checking of component children
Browse files Browse the repository at this point in the history
  • Loading branch information
pastelmind committed Jan 7, 2021
1 parent 3b6a8be commit 19aa2a9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/generate-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ function normalizeAttributeType(attrType: string): string {
// string
if (/EventHandler/i.test(attrType)) return "string";

// vhtml doesn't have a distinct node type--all components become strings.
if (attrType === "ReactNode") return "string";
// vhtml doesn't have a distinct node type--the serializer accepts any value.
// (arrays of any depth are flattened and concatenated)
if (attrType === "ReactNode") return "any";

// vhtml doesn't convert style objects to string, so CSSProperties isn't
// supported.
Expand Down Expand Up @@ -262,6 +263,9 @@ function generateJsxTypesForVhtml(
// A functional pseudo-component returns a string as "element"
writer.writeLine(`type Element = string;`);

// Enable strict type checking for children (TypeScript 2.3+)
writer.writeLine(`interface ElementChildrenAttribute { children: {}; }`);

writer.writeLine(intrinsicElementsInterface.getText());
extractedInterfaceNodes.forEach((node) => {
// If the interface has no properties, convert it to a type alias, using
Expand Down

0 comments on commit 19aa2a9

Please sign in to comment.