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

Feature Request: $attrs type enhancement #181

Closed
Zcating opened this issue Nov 18, 2020 · 3 comments
Closed

Feature Request: $attrs type enhancement #181

Zcating opened this issue Nov 18, 2020 · 3 comments

Comments

@Zcating
Copy link

Zcating commented Nov 18, 2020

const Child = defineComponent({
  props: {
    label: String
  },
  setup(_, ctx) {
    return () => [
      <div>{_.label}</div>,
      <input {...ctx.attrs}/>
    ];
  }
});

const Parent = defineComponent(() => {
  return () => <Child label="test" placeholder="please input"/>;
});

This code will show a error as following.

Type '{ label: string; placeholder: string; }' is not assignable to type 'IntrinsicAttributes & Partial<{}> & Pick<Readonly<{} & { label?: string | undefined; }> & VNodeProps & AllowedComponentProps & ComponentCustomProps, "label" | ... 9 more ... | "class">'.
Property 'placeholder' does not exist on type 'IntrinsicAttributes & Partial<{}> & Pick<Readonly<{} & { label?: string | undefined; }> & VNodeProps & AllowedComponentProps & ComponentCustomProps, "label" | ... 9 more ... | "class">'

@Amour1688
Copy link
Member

You should declare type in Child component.

@Amour1688
Copy link
Member

import { defineComponent, ExtractPropTypes, HTMLAttributes } from 'vue';

const childProps = {
  label: String
}

export type ChildProps = ExtractPropTypes<typeof childProps> & HTMLAttributes

const Child = defineComponent<ChildProps>({
  setup(_, ctx) {
    return () => [
      <div>{_.label}</div>,
      <input {...ctx.attrs}/>
    ];
  }
});

Child.props = childProps

const Parent = defineComponent(() => {
  return () => <Child label="test" placeholder="please input"/>;
});

@Zcating
Copy link
Author

Zcating commented Nov 29, 2020

Accepted.

@Zcating Zcating closed this as completed Nov 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants