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

Use typescript definition for auto completing events and slots in template #1100

Open
znck opened this issue Feb 18, 2019 · 1 comment
Open

Comments

@znck
Copy link
Member

znck commented Feb 18, 2019

Attribute type completion in TSX works if the .vue file provides type definitions.

For example:

Attribute name autocomplete

Attribute value autocomplete

Type definition for base-button.vue:

import { HTML, Components } from '@uxx/prop-types'
import { IconName } from '@uxx/icon'

type Children =
  | any
  | JSX.Element[]
  | {
      icon(): JSX.Element[]
    }
  | {
      leadingIcon?(): JSX.Element[]
      default(): JSX.Element[]
      trailingIcon?(): JSX.Element[]
    }

export type Props<T = never, C = Children> = T &
  JSX.ElementChildrenAttribute<C> & {
    color?:
      | 'primary'
      | 'secondary'
      | 'accent'
      | 'success'
      | 'danger'
      | 'warn'
      | 'info'
    variant?: 'filled' | 'outline' | 'text'
    block?: boolean
    leadingIcon?: IconName
    trailingIcon?: IconName
    icon?: IconName
  }

export interface BaseButton {
  props: Props
  config: {
    routerLink: string
  }

  (props: Props<Components.RouterLink>): JSX.Element
  (props: Props<HTML.A>): JSX.Element
  (props: Props<HTML.Button>): JSX.Element
}

const button: BaseButton

export default button

Open questions:

  1. How to type events and slots?
  2. A standard type API for Vue 2.x and 3.

Example:

https://github.com/znck/vetur-example

@yoyo930021 yoyo930021 changed the title Use typescript definition for auto completing attributes, events and slots in template Use typescript definition for auto completing events and slots in template Jun 21, 2021
@isamyh
Copy link

isamyh commented Jul 10, 2021

This is: needed 👍

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

No branches or pull requests

3 participants