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

In a packager environment like Vite, use typia in Vue files, and just run transform for preprocessing without emit for js. #990

Open
moheng233 opened this issue Mar 5, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@moheng233
Copy link

moheng233 commented Mar 5, 2024

How I got this idea

I want to make a form library that is as convenient as possible and has input validation and error prompts without template code.

He is based on Typescript and Typia, It looks like this to use.

const [field, form] = useForm({
    email: "" as string & tags.Format<"email"> & tags.MaxLength<30>,
    password: "" as string & tags.MinLength<8> & tags.MaxLength<20>
}, {
    onValidate(data) {
        return typia.validate(data);
    },
    onSubmit(data) {
        console.log(data);
        return false;
    }
});
<CForm :context="form">
    <InputText type="email" v-model="field.email.value"/>
    <Password v-model="field.password.value"></Password>
    <CFormSubmit v-slot="{ submit }">
        <Button @click="submit"></Button>
    </CFormSubmit>
</CForm>

In the process, I found out that VITE's TypeScript2 plugin doesn't handle TS in Vue, so I added *.vue to the include path of the plugin. It worked, but because it was preprocessed by Vue and stripped of the type information, it couldn't generate the completed typia validation function.

However, if you advance the compilation process of TypeScript before the Vue plugin, then the compiler macros of Vue will not work.

So, we need a preprocessor that can run before the vue build process, handle TS with types and emit TS.

Functional implementation

So I tried to make a demo using unplugin, which I only tested on vite.
unplugin-vue-typia
I'd like to know your thoughts and suggestions.

@moheng233
Copy link
Author

I have a more vague idea. I think that if the validation function is generated into a separate virtual module, it can effectively speed up the build.

This would be similar to the current generate pattern, but more flexible.

@samchon samchon added enhancement New feature or request good first issue Good for newcomers labels Mar 11, 2024
@samchon
Copy link
Owner

samchon commented Mar 11, 2024

I don't develop vue and front-end applications, so I have no insight into your suggestions. If you think the plugin you created is worthy of being widely distributed to many front-end developers, please send a PR with installation instructions in the document below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants