Skip to content

feat(types): add core-free-icons subpath type shim#5

Open
ramonclaudio wants to merge 2 commits intohugeicons:mainfrom
ramonclaudio:feat/core-free-icons-subpath-types
Open

feat(types): add core-free-icons subpath type shim#5
ramonclaudio wants to merge 2 commits intohugeicons:mainfrom
ramonclaudio:feat/core-free-icons-subpath-types

Conversation

@ramonclaudio
Copy link
Copy Markdown

@ramonclaudio ramonclaudio commented Apr 22, 2026

Adds ambient types for @hugeicons/core-free-icons subpath imports that auto-load when @hugeicons/react is installed.

The icon package advertises subpath exports via "./*" but dist/types/ only ships the barrel index.d.ts, so subpath imports resolve at runtime but TypeScript can't find types under node16/nodenext/bundler resolution. A project importing 32 icons pays 6.2 MB of pre-bundled JS in dev vs 33 KB for subpath imports. 194× bigger for zero runtime benefit.

core-free-icons source doesn't seem to be public, so @hugeicons/react is the closest public surface, and it already owns IconSvgElement.

Changes:

  • src/core-free-icons.d.ts: ambient declaration for @hugeicons/core-free-icons/* typed as IconSvgElement
  • src/index.ts: triple-slash path reference so the declaration auto-loads
  • rollup.config.mjs: copyAmbientTypes() writeBundle hook copies the file into dist/types/ and re-injects the reference into the emitted index.d.ts (rollup-plugin-dts strips reference directives during bundling)
  • README.md: Subpath imports bullet in the Performance list
import SearchIcon from "@hugeicons/core-free-icons/SearchIcon"
<HugeiconsIcon icon={SearchIcon} />

Barrel imports keep working. Verified end-to-end against a TanStack Start project (33 icons, tsc --noEmit clean with the fork linked and no local shim).

Addresses #3.

@hugeicons/core-free-icons advertises subpath exports via "./*" but only
ships a barrel index.d.ts, so subpath imports resolve at runtime but TS
can't find types under node16/nodenext/bundler resolution (see hugeicons#3).

Ships an opt-in shim as @hugeicons/react/core-free-icons that declares
the wildcard module with IconSvgElement. Consumers reference it once:

  /// <reference types="@hugeicons/react/core-free-icons" />

Removable when core-free-icons emits per-icon .d.ts files.
The previous shape pulled IconSvgElement (readonly only) from
@hugeicons/react. Switch to the IconSvgObject union (mutable | readonly)
that core-free-icons itself uses for its barrel exports, so subpath and
barrel imports type identically.

HugeiconsIcon still accepts the value either way (mutable arrays are
assignable to readonly), so this is consistent only, no behavior change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant