-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[QUESTION] How to allow HTML attributes as props while using Typescript JSX? #3452
Comments
You can use functional components for that purpose import { FunctionalComponent } from 'vue'
const MyInput: FunctionalComponent<InputHTMLAttributes & { foo?: string}> = (props) => {
return <input {...props}/>
}
const el = <MyInput foo="str" autofocus type="xxx" /> For |
when i define functional component props it will display type errors
import { defineComponent, FunctionalComponent } from 'vue'
interface FuncCompProps {
p1: string
p2: number
onP1(): void
}
const FuncComp: FunctionalComponent<FuncCompProps> = (props, ctx) => {
return <div>{props.p1}</div>
}
FuncComp.inheritAttrs = false
FuncComp.displayName = 'Func'
FuncComp.props = {
p1: String,
p2: Number,
onP1: {
type: Function,
}
} and i want to define stateful component like a union one style. the below code is interface StateFulCompProps {
s1: string
s2: number
onS1(): void
}
const StateFulComp = defineComponent<StateFulCompProps>((props, ctx) => {
return () => <div>{props.s1}</div>
})
StateFulComp.inheritAttrs = false
StateFulComp.displayName = 'StateFulComp'
StateFulComp.props = {
s1: String,
s2: Number,
onS1: Function,
} in webstorm ide has some mistakes
how can i explicit declare the component props type in stateful coponent ? @HcySunYang thanks |
Version
3.0.7
Reproduction link
https://github.com/sanjade/vue3-bug
Steps to reproduce
First of all, I know this kind of issue shouldn't be asked here but I just wanted to tell you that I did try asking the question in StackOverflow. However it has no response and it's been 2 days.
What is expected?
Suppose I have this input component:
Now, I use this component like so and provide
type="password"
attribute:I expect Typescript not to throw any error.
What is actually happening?
But Typescript complains in
App.tsx
:How do you specify that
InputHTMLAttributes
are also allowed as props in theinput.tsx
component?The text was updated successfully, but these errors were encountered: