From a430ca4373ece3be35e9dc817637ff5192e9624e Mon Sep 17 00:00:00 2001 From: Mehdi Lahlou Date: Mon, 13 Nov 2023 09:30:48 +0100 Subject: [PATCH] types: add type inference for `Story` and `Variant` slots items (fixes #622) (#623) --- packages/histoire-plugin-vue/components.d.ts | 58 ++++++++++++++++---- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/packages/histoire-plugin-vue/components.d.ts b/packages/histoire-plugin-vue/components.d.ts index c5cc28ef..6107969a 100644 --- a/packages/histoire-plugin-vue/components.d.ts +++ b/packages/histoire-plugin-vue/components.d.ts @@ -53,10 +53,6 @@ interface VueStoryProps { * Layout of the story. */ layout?: StoryLayout - /** - * Function that returns the intial state. Will be used as default value for variants. - */ - initState?: () => Record /** * A function to configure the Vue application. This will be the default for the variants in the story. */ @@ -109,10 +105,31 @@ interface VueStoryProps { meta?: StoryMeta } -declare const VueStoryComponent: import('vue').DefineComponent< -TypePropsToRuntimeProps, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, Readonly>> & {}, {} +type VueStoryComponent = import('vue').DefineComponent< +TypePropsToRuntimeProps, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, Readonly>> & {}, import('vue').ExtractDefaultPropTypes>, import('vue').SlotsType > +interface VueStoryPropsGeneric> { + initState?: () => S +} + +interface VueStoryInternalPropsGeneric> { + readonly $props: { + /** + * Function that returns the intial state. Will be used as default value for variants. + */ + initState?: () => S + } + readonly $slots: { + default: import('vue').Slot<{ state: S }> + controls: import('vue').Slot<{ state: S }> + } +} + +type VueStoryComponentGeneric = new = Record>(props: VueStoryPropsGeneric) => VueStoryInternalPropsGeneric; + +declare const VueStoryComponent: VueStoryComponent & VueStoryComponentGeneric + declare const MeowVueStoryComponent: import('vue').Component> // @@ -126,10 +143,6 @@ interface VueVariantProps { * Id of the variant used in the URL. By default, the id is automatically generated with the index of the variant in the list. Setting an id manually will ensure the URL parameter doesn't change with the order of the variants in the story. */ id?: string - /** - * Function that returns the intial state. - */ - initState?: () => Record /** * A function to configure the Vue application. */ @@ -174,10 +187,31 @@ interface VueVariantProps { variant?: VariantMeta } -declare const VueVariantComponent: import('vue').DefineComponent< -TypePropsToRuntimeProps, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, Readonly>> & {}, {} +type VueVariantComponent = import('vue').DefineComponent< +TypePropsToRuntimeProps, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, Readonly>> & {}, import('vue').ExtractDefaultPropTypes>, import('vue').SlotsType > +interface VueVariantPropsGeneric> { + initState?: () => S +} + +interface VueVariantInternalPropsGeneric> { + readonly $props: { + /** + * Function that returns the intial state. + */ + initState?: () => S + } + readonly $slots: { + default: import('vue').Slot<{ state: S }> + controls: import('vue').Slot<{ state: S }> + } +} + +type VueVariantComponentGeneric = new = Record>(props: VueVariantPropsGeneric) => VueVariantInternalPropsGeneric; + +declare const VueVariantComponent: VueVariantComponent & VueVariantComponentGeneric + // Register global components declare module 'vue' {