From 9d6296c79dd728c76453bdfe080a482ef8a7e659 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Sat, 1 Mar 2025 11:11:04 +0100 Subject: [PATCH] Optimize the Components type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The way we used `ElementType` caused a significant increase of resource usage for TypeScript. I can’t really explain it, but this fixes it. I’m personally inclined to say people should avoid using the `JSX` namespace, but I see no other way around it. Without this change, autocompletion in my editor takes a noticable time to load. Now it’s instant. On my machine this halves the time of running `tsc -b` from ~15s to ~7s. Closes #883 --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 7696047..1e2a4a1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,7 @@ /** * @import {Element, Nodes, Parents, Root} from 'hast' * @import {Root as MdastRoot} from 'mdast' - * @import {ComponentProps, ElementType, ReactElement} from 'react' + * @import {ComponentType, JSX, ReactElement} from 'react' * @import {Options as RemarkRehypeOptions} from 'remark-rehype' * @import {BuildVisitor} from 'unist-util-visit' * @import {PluggableList, Processor} from 'unified' @@ -29,7 +29,7 @@ /** * @typedef {{ - * [Key in Extract]?: ElementType & ExtraProps> + * [Key in keyof JSX.IntrinsicElements]?: ComponentType | keyof JSX.IntrinsicElements * }} Components * Map tag names to components. */