Skip to Content
vitus·labs
Rocketstyle

Types Reference

All exported types from @vitus-labs/rocketstyle with full definitions.

Component Types

RocketStyleComponent

The main rocketstyle component type. Extends IRocketStyleComponent and includes dynamically-generated dimension chain methods (e.g., .sm(), .lg(), .primary()).

Generic parameters:

ParamDescription
OAOriginal component props (from the base component)
EAExtended props (accumulated from .attrs() calls)
TTheme type (from .theme())
CSSCustom CSS theme properties
SStatics (from .statics())
HOCHigher-order components (from .compose())
DDimensions configuration
UBUse booleans flag
DKPDimension key props (typed options per dimension)

Every chain method returns a new RocketStyleComponent with updated generics — this is how TypeScript tracks accumulated configuration through the builder chain.

IRocketStyleComponent

The core interface defining all chain methods and static properties:

interface IRocketStyleComponent<OA, EA, T, CSS, S, HOC, D, UB, DKP> {
  // Chain methods (each returns new RocketStyleComponent)
  config(options: ConfigAttrs): RocketStyleComponent
  attrs(param, config?): RocketStyleComponent
  theme(param): RocketStyleComponent
  styles(param: StylesCb): RocketStyleComponent
  compose(param: ComposeParam): RocketStyleComponent
  statics(param): RocketStyleComponent

  // Output methods
  meta: S                          // Access statics
  getStaticDimensions(theme): {    // Dimension introspection
    dimensions: DKP
    useBooleans: UB
    multiKeys: MultiKeys<D>
  }                                // (runtime result also includes `keywords`)
  getDefaultAttrs(props, theme, mode): Record<string, unknown>

  // Type introspection (compile-time only)
  readonly $$rocketstyle: ExtractDimensions<D, DKP>
  readonly $$originTypes: OA
  readonly $$extendedTypes: EA
  readonly $$types: MergedFinalProps

  // Markers
  IS_ROCKETSTYLE: true
  displayName: string
}

RocketComponentType

Runtime type guard for any rocketstyle component:

type RocketComponentType = ElementType & {
  IS_ROCKETSTYLE: true
  $$rocketstyle: Record<string, unknown>
}

Used by isRocketComponent() for runtime checks, and by rocketstories for detecting rocketstyle components.

Configuration Types

ConfigAttrs

Options for the .config() chain method:

type ConfigAttrs = Partial<{
  name: string              // Display name for debugging
  component: ElementType    // Replace the base component
  provider: boolean         // Enable local context provider
  consumer: ConsumerCb      // Map parent provider state to props
  DEBUG: boolean            // Enable debug mode (data-rocketstyle attribute)
  inversed: boolean         // Invert theme mode (light↔dark)
  passProps: (keyof DimensionBooleanAttrs)[]  // Boolean shorthand props to forward (only when useBooleans is true; `never` otherwise)
  styled: boolean           // Wrap in styled() (default: true)
}>

AttrsCb

Callback form for .attrs():

type AttrsCb<Props, Theme> = (
  props: Partial<Props>,
  theme: Theme,
  helpers: {
    mode?: 'light' | 'dark'
    isDark?: boolean
    isLight?: boolean
    createElement: typeof render
  },
) => Partial<Props>

At runtime the helpers object is { render, mode, isDark, isLight } — the render() utility is passed under the key render, not createElement as the type declares. Read it as helpers.render (cast if needed) until the type is corrected.

Dimension Types

Dimensions

Configuration mapping dimension method names to their output prop names:

type Dimensions = Record<string, DimensionValue>

type DimensionValue =
  | string                              // Simple: prop name string
  | {
      propName: string
      multi?: boolean                   // Multi-select support
      transform?: boolean               // Evaluated last; values receive the accumulated theme
    }

Default dimensions:

MethodProp NameMultiTransform
states'state'nono
sizes'size'nono
variants'variant'nono
multiple{ propName: 'multiple', multi: true }yesno
modifiers{ propName: 'modifier', multi: true, transform: true }yesyes

DimensionCallbackParam

Parameter type for dimension chain methods (e.g., .primary(), .sm()):

type DimensionCallbackParam<Theme, CSSTheme> =
  | Record<string, boolean | null | DeepPartial<CSSTheme>>  // Static object
  | ((
      theme: Theme,
      mode: ThemeModeCallback,
      css: Css,
    ) => Record<string, boolean | null | DeepPartial<CSSTheme>>)  // Callback

ExtractDimensionProps

Extracts the final component props from dimensions. When useBooleans is true, includes boolean shorthand props alongside the dimension prop names:

// With useBooleans=true:
// props = { state?: 'primary' | 'danger', primary?: boolean, danger?: boolean }

// With useBooleans=false:
// props = { state?: 'primary' | 'danger' }

ExtractDimensions

Extracts dimension prop names and their available options. Used for the $$rocketstyle introspection property:

// If dimensions have states: { primary: {...}, danger: {...} }
// $$rocketstyle = { state: { primary: true, danger: true } }

Theme & Style Types

ThemeCb

Callback for .theme():

type ThemeCb<CSSTheme, Theme> = (
  theme: Theme,
  mode: ThemeModeCallback,
  css: Css,
) => Partial<CSSTheme>

ThemeModeCallback

Higher-order function for light/dark value selection:

type ThemeModeCallback = <A, B>(
  light: A,
  dark: B,
) => (mode: 'light' | 'dark') => A | B

The returned function is branded (Symbol.for('vl.themeModeCallback')) so getThemeByMode() can tell it apart from other function values.

Usage in .theme():

.theme((theme, mode) => ({
  color: mode('black', 'white'),       // Returns thunk: (mode) => 'black' | 'white'
  background: mode('#fff', '#1a1a1a'), // Resolved later by getThemeByMode()
}))

ThemeModeKeys

type ThemeModeKeys = 'light' | 'dark'

StylesCb

Callback for .styles():

type StylesCb<CSSTheme> = (
  css: RocketCss<CSSTheme>,
) => ReturnType<Css>

The css function provides typed interpolation props:

RocketStyleInterpolationProps

Props available inside CSS interpolation functions in .styles():

type RocketStyleInterpolationProps<CSSTheme> = {
  $rocketstyle: CSSTheme    // Merged theme from all .theme() calls
  $rocketstate: {            // Active dimension values
    [dimensionProp: string]: string | string[]
    pseudo: Partial<PseudoState>  // hover, focus, active, pressed
  }
} & Record<string, any>     // Plus any other props

Provider & Consumer Types

RocketProviderState

State shape provided by a rocketstyle context provider:

type RocketProviderState<T> =
  T extends RocketComponentType
    ? Partial<T['$$rocketstyle']> & { pseudo: PseudoState }
    : T

For rocketstyle components, includes partial dimension options plus pseudo-state. For non-rocketstyle types, passes through as-is.

ConsumerCb

Top-level consumer callback for .config({ consumer }):

type ConsumerCb = (
  ctx: (attrs: RocketProviderState) => Partial<DimensionProps & { pseudo: PseudoState }>
) => Partial<DimensionProps & { pseudo: PseudoState }>

Maps parent provider state to the current component's dimension props:

.config({
  consumer: (ctx) =>
    ctx((parentState) => ({
      state: parentState.state,
      pseudo: parentState.pseudo,
    })),
})

Composition Types

ComposeParam

Object for .compose() — maps named HOCs:

type ComposeParam = Record<string, GenericHoc | null | undefined | false>

Setting a key to null/undefined/false removes a previously added HOC.

GenericHoc

HOC signature:

type GenericHoc = (component: ElementType) => ElementType

Utility Types

isRocketComponent

Runtime type guard function:

const isRocketComponent: (component: unknown) => boolean

Returns true if the component has the IS_ROCKETSTYLE marker. Uses Object.hasOwn() for safe property check.

Type Introspection Symbols

Every rocketstyle component exposes these read-only properties for TypeScript inference:

SymbolTypePurpose
$$rocketstyleExtractDimensions<D, DKP>Available dimension values
$$originTypesOAOriginal base component props
$$extendedTypesEAProps added via .attrs()
$$typesMergedFinal resolved props type

These are compile-time only — they have no runtime value. They enable type inference when extending rocketstyle components or using them with rocketstories.

ExtractProps

ExtractProps<C> derives the prop type of the wrapped component (OA). It is overload-aware: for a component declared with multiple call signatures it returns the union of every overload's first parameter, not just the last.

// List/Iterator expose 4 overloads (Simple / Object / Children / Loose).
const StyledList = rocketstyle()({ component: List, name: 'StyledList' })

// StyledList's prop surface is the UNION of List's overloads — the
// iterator API survives the wrap. `<StyledList data={users} … />`
// keeps working; it does NOT collapse to List's last signature.

Resolution order: 4-overload → 3-overload → 2-overload → single-callable (ComponentType<infer P>) → passthrough. Non-overloaded components are unaffected (single-callable path, identical to prior behaviour).

This is what makes rocketstyle()({ component: List }) usable: before 2.3.0, ExtractProps picked only the last overload (ChildrenProps), so wrapping List lost the data/itemKey/iterator surface entirely. Combined with the elements LooseProps fallback overload (2.5.0), forwarding Partial<(typeof StyledList)['$$types']> round-trips. See PRs #222 / #229.

Trade-off: generic overload type-params resolve to their constraint upper bound (<T extends ObjectValue> → ObjectValue), so per-T narrowing inside itemProps callbacks is lost through the wrap (direct <List> calls keep it). Annotate explicitly if needed: itemProps={(item: User) => …}.

Full Exports

import { rocketstyle, isRocketComponent, Provider, context } from '@vitus-labs/rocketstyle'

import type {
  RocketStyleComponent,
  IRocketStyleComponent,
  RocketComponentType,
  RocketProviderState,
  ConsumerCtxCBValue,
  ConsumerCtxCb,
  ConsumerCb,
  DimensionCallbackParam,
  DimensionProps,
  Dimensions,
  DimensionValue,
  StylesCb,
  RocketStyleInterpolationProps,
  ThemeCb,
  ThemeModeCallback,
  ThemeModeKeys,
  ConfigAttrs,
  AttrsCb,
  ComposeParam,
  GenericHoc,
  ExtractDimensionProps,
  ExtractDimensions,
  ExtractProps,
  ElementType,
  MergeTypes,
  Rocketstyle,
  DefaultProps,
  IsRocketComponent,
  StylesDefault,
  TDKP,
  ThemeDefault,
  ThemeMode,
  TObj,
  TProvider,
} from '@vitus-labs/rocketstyle'
Edit on GitHub

Last updated on

On this page