Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional component props in the Options Api are described in .d.ts not correct #211

Open
3 tasks done
ivanmem opened this issue May 17, 2023 · 6 comments
Open
3 tasks done
Labels
pending Need further confirmation

Comments

@ivanmem
Copy link

ivanmem commented May 17, 2023

Describe the bug

The plugin does not take into account that "error" is an optional parameter.

Component.vue:

props: {
 error: String as PropType<string>,
},

Like now:

Component.vue.d.ts:

 error: PropType<string>;

It should be:

Component.vue.d.ts:

 error?: PropType<string>;

Reproduction

I'll create it later if anyone needs it.

Steps to reproduce

No response

System Info

"vue": "3.3.2",
"vite": "4.3.5",
"vite-plugin-dts": "2.3.0",

Validations

@qmhc
Copy link
Owner

qmhc commented Jun 27, 2023

Vue props default optional if without required.

@ivanmem
Copy link
Author

ivanmem commented Jun 27, 2023

@qmhc even if you specify required: false - the plugin still does not take this into account.

@qmhc
Copy link
Owner

qmhc commented Jun 27, 2023

It's unnecessary, Vue (Volar) will infer the definition of props, and will know which porp is required.

image

image

image

image

@ivanmem
Copy link
Author

ivanmem commented Jun 27, 2023

@qmhc webstorm Volar appeared only in beta version.

@qmhc
Copy link
Owner

qmhc commented Jun 27, 2023

Currently plugin using Volar as drive (in v3), I think we should wait Volar update. Because Volar finally will slove this solution and we shouldn't work repeatedly.

@qmhc qmhc added the pending Need further confirmation label Jun 30, 2023
@StevenTew
Copy link

StevenTew commented Oct 10, 2023

If it helps, I see the same issue with optional React prop types

My .jsx file has the following defined:

const MessageBox = ({
    center,
    children,
    icon,
    onDismiss,
    size,
    tone,
    ...rest
}) => { ... };

MessageBox.defaultProps = {
    center: false,
    children: null,
    icon: null,
    onDismiss: null,
    size: null,
    tone: null,
};

MessageBox.propTypes = {
    /** Center the content horizontally */
    center: PropTypes.bool,

    /** React elements for display inside MessageBox */
    children: PropTypes.node,

    /** A single ui-icon component */
    icon: PropTypes.element,

    /** Your callback function for the MessageBox close button */
    onDismiss: PropTypes.func,

    /** Controls spacing, text and icon size */
    size: PropTypes.oneOf(['large', 'tiny']),

    /** Controls the contextual tone */
    tone: PropTypes.oneOf([
        'neutral',
        'info',
        'success',
        'critical',
        'promote',
    ]),
};

The generated definition file is this (optional props are not listed as optional):

export default MessageBox;
declare function MessageBox({ center, children, icon, onDismiss, size, tone, ...rest }: {
    [x: string]: any;
    center: any;
    children: any;
    icon: any;
    onDismiss: any;
    size: any;
    tone: any;
}): import("react/jsx-runtime").JSX.Element | null;
declare namespace MessageBox {
    namespace defaultProps {
        const center: boolean;
        const children: null;
        const icon: null;
        const onDismiss: null;
        const size: null;
        const tone: null;
    }
    namespace propTypes {
        const center_1: PropTypes.Requireable<boolean>;
        export { center_1 as center };
        const children_1: PropTypes.Requireable<PropTypes.ReactNodeLike>;
        export { children_1 as children };
        const icon_1: PropTypes.Requireable<PropTypes.ReactElementLike>;
        export { icon_1 as icon };
        const onDismiss_1: PropTypes.Requireable<(...args: any[]) => any>;
        export { onDismiss_1 as onDismiss };
        const size_1: PropTypes.Requireable<string>;
        export { size_1 as size };
        const tone_1: PropTypes.Requireable<string>;
        export { tone_1 as tone };
    }
}
import PropTypes from 'prop-types';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending Need further confirmation
Projects
None yet
Development

No branches or pull requests

3 participants