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

Commit

Permalink
Revert "feat: Enable type checking of component children"
Browse files Browse the repository at this point in the history
This reverts commit 19aa2a9.

This won't work, because vhtml handles the `props.children` attribute in
a way different from how TypeScript expects things.

TypeScript believes that:

- A component with no child receives props.children === undefined
- A component with one child receives props.children === typeof child
- A component with multiple children receives [...children]

However, vhtml always wraps children in an array, even if there is only
0 or 1 child.

Because of this, enforcing strict type checking on children would result
in incorrect type checks that could be actively harmful.

See more discussion and example at:

- developit/vhtml#19 (comment)
  • Loading branch information
pastelmind committed Jan 7, 2021
1 parent 19aa2a9 commit 34f68a9
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/generate-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ function normalizeAttributeType(attrType: string): string {
// string
if (/EventHandler/i.test(attrType)) 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 have a distinct node type--all components become strings.
if (attrType === "ReactNode") return "string";

// vhtml doesn't convert style objects to string, so CSSProperties isn't
// supported.
Expand Down Expand Up @@ -263,9 +262,6 @@ 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 34f68a9

Please sign in to comment.