Skip to content

Function: getDefaultsForPropFactory()

ts
function getDefaultsForPropFactory<T, ExtractedPublicProperties>(
  factory: T,
): ExtractedPublicProperties;

Extracts default values from a Vuetifiable props factory and returns them as a runtime object. This is useful for getting default prop values for component initialization or testing.

The function handles different types of default values:

  • Primitive defaults (string, number, boolean) are returned as-is
  • Reference type defaults (Object, Array, etc.) defined as functions are called to get fresh instances
  • Props without defaults are completely excluded from the result
  • The result is cleaned to ensure no undefined values slip through

Type safety is enforced at both compile-time (via NonNullable) and runtime (via stripUndefinedValuesFromObject).

Type Parameters

Type ParameterDefault typeDescription
T extends <Defaults>(defaults?: Defaults) => AppendDefault<PropsOptions, Defaults><Defaults>(defaults?: Defaults) => AppendDefault<PropsOptions, Defaults>The props factory type, constrained to PropFactory
ExtractedPublicPropertiesExtractPublicDefaultPropTypes<T>The extracted public properties with non-nullable defaults

Parameters

ParameterTypeDescription
factoryTThe Vuetifiable props factory function

Returns

ExtractedPublicProperties

A clean object containing only the default values for public props that have defaults, guaranteed to be free of undefined values

Example

typescript
const myPropsFactory = propsFactory(
  {
    title: { type: String, default: "Hello World" },
    items: { type: Array, default: () => [] },
    settings: { type: Object, default: () => ({ theme: "dark" }) },
    count: { type: Number, default: 0 },
    enabled: { type: Boolean }, // no default - will be excluded
    internal: { type: String, default: "secret", __internal: true }, // private - will be excluded
  },
  "MyComponent",
);

const defaults = getDefaultsForPropFactory(myPropsFactory);
// Result: { title: 'Hello World', items: [], settings: { theme: 'dark' }, count: 0 }
// Note: 'enabled' and 'internal' are not included - no defaults or not public