TypeScript standard
TypeScript is part of the product. Public types should make valid use easy to discover and invalid use difficult to express without requiring type gymnastics that maintainers cannot explain.
The shared configuration enables strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes, noImplicitOverride, useUnknownInCatchVariables, and related consistency checks. skipLibCheck remains enabled because third-party declaration compatibility is outside this library's control; all project source and emitted declarations are still checked.
The workspace currently pins TypeScript 6 even though TypeScript 7 is available, because the current typescript-eslint compiler integration does not yet support the TypeScript 7 API. Revisit the pin once the lint stack declares support; do not upgrade only the compiler and silently lose type-aware linting.
Rules
- Do not use routine
any; useunknownat untrusted boundaries and narrow it. - Avoid non-null assertions. When an invariant makes one necessary, document the invariant next to the assertion.
- Avoid assertions used only to silence inference. Prefer validation, narrowing, or a clearer model.
- Use meaningful generic parameter names for public APIs.
- Prefer readable types over deeply recursive or distributive cleverness.
- Type props, emits, slots, configuration, events, and exposed methods intentionally.
- Make cross-package type relationships explicit. Do not duplicate a contract owned by another package and rely on incidental structural compatibility; import and use the canonical type directly, extend or intersect it when adding fields, or use a named typed adapter when the representations intentionally differ.
- Preserve consumer types through accessors and configuration where practical.
- Use type-only imports and exports when a symbol has no runtime role.
Compile-time API tests should be added when the first meaningful inference or generic contract exists. An empty type-test harness now would protect nothing; future tests may use vue-tsc fixtures or a dedicated tool if diagnostics need more precise assertions.
strictTemplates
GhostVue's public types support vueCompilerOptions.strictTemplates for native attributes, listeners and the theme utility attributes. A consumer who turns it on gets errors for real mistakes, such as a misspelled prop, and not for ordinary usage. It stays optional for consumers.
Each failure group has a fixture in packages/themes/type-tests-strict/:
| Group | Fixture | Status |
|---|---|---|
1. Native attributes and listeners (id, name, placeholder, href, role, @click) | FallthroughAttributes.vue | Passes |
2. Props for a component as target (:as="RouterLink" to="/settings") | PolymorphicAs.vue | Passes for GhostLink and GhostBreadcrumbLink only |
3. v-model onto a narrower ref than the emitted union | ModelUnions.vue | Known gap |
4. data-gradient and data-material on plain elements and components | UtilityAttributes.vue | Passes |
AllComponents.ts checks groups 1 and 4 for every component exported from @ghostvue/vue and @ghostvue/themes, so a new component that does not admit its host attributes fails without anyone adding it to a fixture. QueryBuilder.vue covers a generic component in a template: GhostQueryBuilder inferred from its fields, a typed template ref, and the value slot narrowed by fieldId for a custom editor. It passes. pnpm types:strict-templates prints the counts, and pnpm types:strict-templates --check runs in pnpm verify:static: it fails on any fixture diagnostic outside the known gaps, and when a known gap's count changes (update KNOWN_GAPS in scripts/strict-templates-baseline.mjs and this section together). vue-tsc reports only the first unknown attribute per element, so counts are lower bounds.
When the fixtures were added, they produced 18 diagnostics (9, 1, 4 and 4 for groups 1 to 4). They now produce 4 (0, 0, 4 and 0). Group 2 is fixed only for GhostLink and GhostBreadcrumbLink, which PolymorphicAs.vue covers; other components that accept as still type only their default target (see Polymorphic as). Library source templates produce 84 more, mostly data-part on plain elements. The check reports those but does not fail on them, because consumers compile against the published declarations, not GhostVue's templates.
Fallthrough attributes
Decision: a component's public prop type is its declared props plus the attributes of the element that receives its fallthrough attributes.
Headless SFCs intersect their props with
GhostHostAttributes<Tag, Omitted>behind a@vue-ignorecomment:tswithDefaults( defineProps< { disabled?: boolean type?: GhostButtonType } & /* @vue-ignore */ GhostHostAttributes<'button', 'disabled' | 'type'> >(), { disabled: false, type: 'button' }, )@vue-ignorekeeps the attributes out of Vue's runtime prop list, so they stay fallthrough attributes, while vue-tsc and the published declarations include them. Never read them fromprops; useuseAttrs().Tagis the element that receives the attributes. For a polymorphic component it is the defaultastarget. A union ('label' | 'input') admits both elements' attributes, for components that split attributes, such as the choice cards.Omittedlists declared props and emitted events with the same name as a host attribute (disabled,value,dir,onSubmitonGhostForm). Without it the two types intersect and the declared type narrows or becomesnever.pnpm manifestsreports every such collision in a headless SFC, and leaves host attributes out of component manifests and docs API tables.Renderless components (providers and roots that render only their slot, and portals) do not declare host attributes, since Vue has no element to put them on. They are listed in
AllComponents.ts.Themed wrappers export
XComponent as GhostThemedComponent<typeof XComponent, typeof Inner>, whereInneris the component the wrapper forwardsattrsto. The public type is the wrapper's props plus everythingInneraccepts that the wrapper does not redeclare. Generic wrappers that are already cast by hand (GhostSelect,GhostStepper) intersectGhostHostAttributesinto their setup props type. Wrappers of a component with a typedastarget useGhostThemedPolymorphicComponent(see Polymorphicas).The new-component scaffold starts with both patterns.
Type-check cost. Checking the library source is slower: vue-tsc turns a type-declared props object with
withDefaultsinto a runtime props option key by key, so each component's few hundred host attributes go through Vue's prop inference. Checking@ghostvue/vueand@ghostvue/themesfrom source takes about 1.5 and 2.4 times as long as before. The published declarations reference__VLS_Propsdirectly, so consumers do not pay this per-key cost.pnpm manifestsreads a stub whereGhostHostAttributesadds nothing, which keeps its run at its earlier time, and checks collisions against the host element's attribute names instead.
Alternatives considered:
- vue-tsc's
fallthroughAttributesoption infers the attribute type, but only from a single root with inherited attributes or a literalv-bind="$attrs". Most GhostVue components mergeattrsinto computed bindings, so it would miss them. - Casting each export in the generated barrel would keep SFC sources unchanged, but generic SFCs are typed as functions and would lose their type parameters.
- A
data${Capitalize<string>}index signature in every props type would admit any data attribute, but an interface-typed props object (such as aGhostTagsInputPropsvalue passed toh()ormount()) is not assignable to a type with an index signature.
Data and utility attributes
Vue's HTMLAttributes declares no data-* keys, so strict templates reject any data attribute on a plain element, GhostVue or not. On a component, vue-tsc camelizes data-testid to dataTestid before matching it against props.
@ghostvue/themestypes its own utilities: it addsdata-gradientanddata-materialto Vue'sHTMLAttributes(plain elements) anddataGradientanddataMaterialtoGhostCustomAttributes(every GhostVue component). The built-in values autocomplete, and other strings are accepted for theme-defined ones.- For other data attributes, consumers either set
vueCompilerOptions.dataAttributes: ["data-*"], which skips checking them on elements and components, or augmentGhostCustomAttributesin@ghostvue/vuewith camelized keys (dataTestid?: string) for GhostVue components only.
Polymorphic as
Decision: a polymorphic component's attribute type follows its as target. GhostLink and GhostBreadcrumbLink pilot this. Every other component that accepts as still types only its default target: global attributes such as id, role and aria-* work for any target, but attributes specific to another element (href on a component whose default is a button) and props for a component target are not typed. Expand the pattern one component (or family) at a time.
The pattern, as GhostLink uses it:
Headless SFC.
asis a type parameter whose default is the default tag, and the attributes come fromGhostAsAttributes:vue<script setup lang="ts" generic="TTarget extends GhostLinkElement = 'a'"> const { as = 'a', disabled = false } = defineProps< { as?: TTarget | GhostLinkElement disabled?: boolean } & /* @vue-ignore */ GhostAsAttributes<TTarget, 'a', 'as' | 'disabled'> >() </script>GhostAsAttributes<Target, DefaultTag, Declared>gives a tag target's element attributes. For a component target it gives the component's props (required ones stay required, so:as="RouterLink"withouttois an error) plus theDefaultTagattributes the target does not declare, because the target usually renders that element and receives them as fallthrough attributes.Declaredlists the component's own props, which always win.Interceptedlists attributes the component consumes instead of passing to a component target (GhostLinksetshrefon a native anchor only). They are typed?: neverfor a component target, even when the target declares them, so the type never promises the target a value it does not receive. Anything else (noas, an unknown custom element name, a value typed only asComponent) falls back toDefaultTag.Defaults. Use destructure defaults, not
withDefaults. Inside the SFCTTargetis unresolved, andwithDefaultsmaps over the keys of the whole props type, so it cannot find the declared props next to the type-parameterized attributes. Destructure defaults compile to the same runtime defaults, and vue-component-meta reads them for manifests. Afalsedefault for a Boolean prop trips@typescript-eslint/no-useless-default-assignment(Vue casts an absent Boolean prop tofalse); keep it, with a scoped disable, so the manifest still records the default.GhostAsAttributesalso wraps its result in a check that is always true for a concrete target. WhileTTargetis unresolved, that check gives the attributes a constraint with no known keys, instead of an index signature that hides the declared props.Render functions. Two details keep
h(GhostLink, { href }, () => '…')andmount(GhostLink, …)compiling.asis typedTTarget | GhostLinkElement: relating a generic SFC to the non-generic function typeh()expects can infer a single member of the constraint (string), which would then reject the props.no-duplicate-type-constituentsflags the union; disable it on that line with a reason. And slots are optional (default?(): unknown), as in the other generic SFCs, because the function's context parameter requires every declared slot.Default type argument.
= 'a'documents the default target. An omittedasresolves to the anchor through either the default or theDefaultTagfallback.Themed wrapper. A generic SFC is typed as a function, so
GhostThemedComponentsees only its erased signature. Cast the wrapper withGhostThemedPolymorphicComponent<typeof Wrapper, AsTarget, DefaultTag>. Its generic construct signature takes the props, so the template type checker infers the target from:as. The wrapper's own props win over the target's (themedGhostLink'svariantis its own, notGhostButton's). The render function keeps callingh(Inner, ...)(see Render functions).Manifests. vue-component-meta reports the prop type with the type parameter (
GhostLinkElement | TTarget), as it does for other generic SFCs (readonly TValue[]), so the prop description mentionsTTarget.pnpm manifestsreads a stub ofGhostAsAttributesthat adds nothing, likeGhostHostAttributes.Type-check cost. The pilot did not measurably change vue-tsc time (median of three cold runs before and after:
@ghostvue/vue37.0 s and 36.3 s,@ghostvue/themes27.1 s and 26.9 s).Tests. Add the component to
PolymorphicAs.vuefor both the headless and the themed component: a component target with a required prop (RouterLink;vue-routeris a development dependency of@ghostvue/themesfor this fixture only), a@vue-expect-errorfor a missing and for a mistyped required prop, and an element target.Compatibility. An element target now admits only that element's attributes, so
GhostBreadcrumbLink as="button" href="..."becomes an error. Note this in the Changeset.
Until a component adopts the pattern, pass target props in an object, which strict templates do not check per key: <GhostButton :as="RouterLink" v-bind="{ to: '/settings' }">.
v-model unions (group 3)
GhostSlider emits GhostSliderValue (a number, or a two-number tuple with range), and GhostSelect emits string | undefined because it can be cleared. Binding either to a ref<number> or ref<string> is a type error under strict templates. Narrowing the emitted type needs the model type to depend on range or on whether clearing is possible, which is a public API change for each component. The approved typings, with no target release yet, are in the Slider and Select specifications.