npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-tsx-resolve-types

v0.0.4

Published

this is a vite plugin for auto props in tsx

Downloads

20

Readme

tsx-resolve-types

vue3-tsx type annotation parser plugin based on vite.

Install


pnpm add vite-plugin-tsx-resolve-types -D

Usage

In vite.config.ts:

import { defineConfig } from 'vite'
import { tsxResolveTypes } from 'vite-plugin-tsx-resolve-types'
import vueJsx from '@vitejs/plugin-vue-jsx'

export default defineConfig({
    plugins: [
        tsxResolveTypes(),
        vueJsx(),
    ],
})

Example

Props

Supports automatic parsing of props types and generates corresponding props entity objects.

import { defineComponent } from "vue";

export interface Props {
    foo: string
    bar?: number
}

const Single = defineComponent<Props>((props) => {
    return () => {
        return <div>{props.foo}</div>
    }
})

const SingleDefault = defineComponent((props:Props = {foo:'1',bar:'2'})=>{
    return ()=>{
        return <div>{props.foo}</div>
    }
})

const SingleDefault2 = defineComponent<Props>((props = {foo:'1',bar:'2'})=>{
    return () =>{
        return <div>{props.foo}</div>
    }
})

const Setup = defineComponent({
    setup(props:Props){
        return ()=>{
            return <div>{props.foo}</div>
        }
    }
})

const SetupDefault = defineComponent({
    setup(props:Props = {foo:'1',bar:'2'}){
        return ()=>{
            return <div>{props.foo}</div>
        }
    }
})

const SetupDefault2 = defineComponent<Props>({
    setup(props = {foo:'1',bar:'2'}){
        return ()=>{
            return <div>{props.foo}</div>
        }
    }
})

You can separately define a type file import method to use.

// typing.ts
export interface Props {
    foo: string
    bar?: number
}

export const defaultProps:Props = {
    foo:'1',
    bar:2
}
import { defineComponent } from "vue";
import { type Props, defaultProps} from "./typing"

const Single = defineComponent<Props>((props) => {
    return () => {
        return <div>{props.foo}</div>
    }
})

const SingleDefault = defineComponent((props:Props = defaultProps)=>{
    return ()=>{
        return <div>{props.foo}</div>
    }
})

const Setup = defineComponent({
    setup(props:Props){
        return ()=>{
            return <div>{props.foo}</div>
        }
    }
})

const SetupDefault = defineComponent({
    setup(props:Props = defaultProps){
        return ()=>{
            return <div>{props.foo}</div>
        }
    }
})

Emits

Supports automatic parsing of emits types and generates corresponding emits entity objects.

import { defineComponent } from "vue";
export interface Props {
    foo: string
    bar?: number
}

interface Emits {
    'click':[string]
}
const Single = defineComponent((props:Props,ctx:SetupContext<{
    'click':[string]
}>)=>{
    return ()=>{
        return <div onClick={()=>ctx.emit('click','1')}>{props.foo}</div>
    }
})

const TypeSingle = defineComponent<Props>((props,ctx:SetupContext<Emits>)=>{
    return ()=>{
        return <div onClick={()=>ctx.emit('click','1')}>{props.foo}</div>
    }
})

const Setup = defineComponent({
    setup(props:Props,ctx:SetupContext<{
        'click':[string]
    }>) {
        return ()=>{
            return <div onClick={()=>ctx.emit('click','1')}>{props.foo}</div>
        }
    }
})



const TypeSetup = defineComponent({
    setup(props:Props,ctx:SetupContext<Emits>) {
        return ()=>{
            return <div onClick={()=>ctx.emit('click','1')}>{props.foo}</div>
        }
    }
})

License

MIT. Made with ❤️ by aibayanyu20