Jenesius / vue-modal

🖖The progressive and simple modal system for Vue.js v3
https://modal.jenesius.com
MIT License
149 stars 14 forks source link

Type Supporting #78

Closed Jenesius closed 1 year ago

Jenesius commented 1 year ago

When we provide Component we can get the types for props:

import MyComponent from "./mycomponent.vue";
type MyComponentProps = InstanceType<typeof MyComponent>["$props"];

Its will be amazing!

Jenesius commented 1 year ago

I found next solution but its not work for me: link. Trying found something else.

Jenesius commented 1 year ago
type SimpleComponent<T> = {
    props?: T,
    [name: any]: any
}

export default function openModal<P extends SimpleComponent<T>, T>(component: P, props: T, options: PartialModalOptions = {}):Promise<Modal>

But in current solution props is required. Need to fix it.

Jenesius commented 1 year ago

Changes:

type SimpleComponent<T = {}> = Component &  {
    props?: T,
}

export default function openModal<P extends SimpleComponent>(component: P, props: P["props"] | UnwrapRef<P["props"]> = {}, options: PartialModalOptions = {}):Promise<Modal>
{
    return closeModal()
   .then(() => {
       if (modalQueue.value.length) throw ModalError.QueueNoEmpty();
   })
    .then(() => pushModal(component, props, options))
}

Now is working. Continue with fixs and tests

Jenesius commented 1 year ago

Is not working for default vue component(without typescipt annotation)

TS2322: Type 'number' is not assignable to type 'NumberConstructor'.
    11 |                let output = null;
    12 | 
  > 13 |                const modal = await openModal(ModalButton, {value});

Maybe ExtractPropTypes will helpfull..

Jenesius commented 1 year ago

I Stopped on providing computed and ref values to modals. I think is main func and should be suported by library

Jenesius commented 1 year ago

Recomendation WebStorm bug

Jenesius commented 1 year ago

Done! But I think it will work not for everyone. Need check it for big project

Jenesius commented 1 year ago

After adding ComputedRef/ Ref I see the next problem: image After declaration types the TS provide me props and ComputedValues: value or effect

Jenesius commented 1 year ago

For setup component is contuine don't worked.

Jenesius commented 1 year ago

I will merge current branch today after testing. Also I will update preview GIF and add design pack.