Add ForgeComponent type and define overloads

This commit is contained in:
Chris Wanstrath 2026-04-08 14:44:27 -07:00
parent dcf4f1062b
commit 9301aed3e3

View File

@ -1,5 +1,9 @@
import { type TagDef, type HTMLTag, UnitlessProps, NonStyleKeys } from './types'
type ForgeComponent<Parts = {}> =
((props: Record<string, any>) => any) &
{ [K in keyof Parts]: (props: Record<string, any>) => any }
export const styles: Record<string, Record<string, string>> = {}
const themes: Record<string, Record<string, any>> = {}
@ -288,6 +292,8 @@ export function createScope(scope: string) {
}
// the main event
export function define<const T extends TagDef>(name: string, def: T): ForgeComponent<T['parts']>
export function define<const T extends TagDef>(def: T): ForgeComponent<T['parts']>
export function define(nameOrDef: string | TagDef, defIfNamed?: TagDef) {
const def = defIfNamed ?? nameOrDef as TagDef
const name = defIfNamed ? (nameOrDef as string) : anonName(def)