types — public types
src/types/ is the publicly exposed type layer. The difference from core/shared/types (core’s internal union types): this is the base shape used by each UI library’s component Props.
How to import
Section titled “How to import”import type { LhLocaleType, LhLocaleMessages, LhLocaleMessageValue, LhLeaves, LhBaseProps, LhTypes, LhSizes, LhLanguages,} from '@lh-ui/share/types'Export structure
Section titled “Export structure”export * from './locale' // locale-relatedexport * from './components/base' // component base propsglobal.d.ts, theme.ts, and scss.d.ts are ambient declarations; they participate in compilation through tsconfig’s include and are not explicitly exported here.
Locale-related types
Section titled “Locale-related types”| Type | Definition | Purpose |
|---|---|---|
LhLocaleType |
(typeof LH_LANGUAGE_CONST)[keyof typeof LH_LANGUAGE_CONST] |
Union of the six language codes |
LhLocaleMessageValue |
string | readonly LhLocaleMessageValue[] | { readonly [key: string]: LhLocaleMessageValue } |
Language pack leaf node (recursively readonly) |
LhLocaleMessages |
Record<string, LhLocaleMessageValue> |
The language pack as a whole |
LhLeaves<T, Prefix extends string = ''> |
Recursive mapped type | Derives the dotted-path union of every “string leaf” |
LhLocaleOptions |
{ locale: LhLocaleType; messages: LhLocaleMessages } |
The argument shape for lhlocale.use() |
Behavior of LhLeaves
Section titled “Behavior of LhLeaves”type ZhLeaves = LhLeaves<typeof zhCN>// 'common.loading' | 'input.placeholder' | 'input.password' | 'pagination.total' | …- String leaves → the full path (
'input.placeholder'). - Array keys (e.g.
datepicker.months) →never. Arrays are not addressed by key, sot()cannot hit them; onlytm()can reach them. - Objects → recurse into the child keys.
LhLocalePath = LhLeaves<typeof zhCN> gives lhlocale.t() literal autocompletion and spell-checking.
Component base props
Section titled “Component base props”Three generic unions (allowing the business side to extend with custom values):
export type LhTypes<T extends string | undefined = undefined> = T extends string ? LhComponentType | T : LhComponentType
export type LhSizes<T extends string | undefined = undefined> = T extends string ? LhComponentSize | T : LhComponentSize
export type LhLanguages<T extends string | undefined = undefined> = T extends string ? LhComponentLanguage | T : LhComponentLanguageUsage:
type MyType = LhTypes<'brand' | 'dangerous'>// LhComponentType | 'brand' | 'dangerous'LhBaseProps — the base shape of component Props
Section titled “LhBaseProps — the base shape of component Props”export interface LhBaseProps< T extends string | undefined = undefined, S extends string | undefined = undefined, L extends string | undefined = undefined,> { type?: T extends string ? LhTypes<T> : LhTypes size?: S extends string ? LhSizes<S> : LhSizes disabled?: boolean loading?: boolean plain?: boolean block?: boolean icon?: string nativeType?: string href?: string target?: string title?: string alt?: string lang?: L extends string ? LhLanguages<L> : LhLanguages langPath?: string old?: boolean // elderly-friendly mode}Each UI library’s component Props extends LhBaseProps and automatically gets the common fields type / size / disabled / lang — guaranteeing that public prop names are consistent across the whole family (users never have to remember “this library calls it disabled, that one doesn’t have disabled”).
| Field | Semantics |
|---|---|
type |
Semantic color (LhTypes) |
size |
Size tier (LhSizes) |
disabled |
Disabled |
loading |
Loading |
plain |
Plain style (outlined, no fill) |
block |
Block-level width 100% |
icon |
Icon name (the built-in icon set; see the icon section of icons) |
nativeType |
Native button type (submit / reset / button) |
href / target |
The link when rendering as <a> |
title / alt |
Title and alternative text (accessibility) |
lang |
Component-level language override |
langPath |
Custom message-key path prefix |
old |
Elderly-mode toggle (paired with size="x-large"; see constants) |
Ambient global declarations
Section titled “Ambient global declarations”These take effect through tsconfig’s include; no import needed:
interface CSSVariable { [key: string]: string }
interface LhUIConfig { prefix?: string theme?: Record<string, string> locale?: string}
interface InstallOptions { prefix?: string theme?: Record<string, string> locale?: string components?: any[]}These are the ambient types for global configuration options like app.use(LhUI, { prefix: 'x' }). theme.ts is currently an empty placeholder (the theme types live in src/theme/types.ts); scss.d.ts declares the .scss module.
Caveats
Section titled “Caveats”LhBasePropsfields are all optional: every field may be empty; componentsextendsit and tighten as needed (for exampletypeis required on button).- The relationship between
langand the global language:langis a component-level override (<lh-button lang="en-US">) that does not calllhlocale.setLocale— the component selects the language pack internally. - The generic-default gotcha:
LhTypes<undefined>resolves toLhComponentType— passingundefinedas the generic argument yields a different result than passing astringliteral. This is deliberate (theextends string ? ... : ...branch). LH_LANGUAGE_CONSTis not on the types public export surface:types/locale.tsimports it internally for derivation, buttypes/index.tsonly exports./localeand./components/base— to use the constant, import it from@lh-ui/share/constants.
Copyright © 2024-2026 FengMo WenXue