-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
type Inference incorrect of DefineComponent
with HTMLAttributes
#4689
Comments
The cause of this problem is due to this change: #4578 |
const Comp = defineComponent({
props,
setup() {
return <div></div>
},
}) as unknown as DefineComponent<HTMLAttributes & ExtractPropTypes<typeof props>>
const props = {
propA: Number,
propB: [String, Number],
propC: {
type: String,
default: 'true', // required => default
},
}
const Comp = defineComponent({
props,
setup() {
return <div></div>
},
}) as unknown as DefineComponent<HTMLAttributes & ExtractPropTypes<typeof props>>
const render = () => {
const onClick = () => {}
return <Comp propB={'123'} onClick={onClick}></Comp>
} |
/cc @Amour1688 |
This seems to be the bug of And there is a better solution if you want to extends your props const props = {
propA: Number,
propB: [String, Number],
propC: {
type: String,
required: true,
},
}
const Comp = defineComponent<HTMLAttributes & ExtractPropTypes<typeof props>>({
setup() {
return <div></div>
},
})
// for runtime
Comp.props = props |
my final solution is as follows: export const iconProps = {
iconfont: IxPropTypes.bool.def(false),
name: IxPropTypes.string,
rotate: IxPropTypes.oneOfType([Boolean, Number, String]),
}
export type IconProps = IxInnerPropTypes<typeof iconProps> // This is the type used internally
export type IconPublicProps = IxPublicPropTypes<typeof iconProps> // This is the type of exposure to the user
export type IconComponent = DefineComponent<Omit<HTMLAttributes, keyof IconPublicProps> & IconPublicProps>
export type IconInstance = InstanceType<DefineComponent<IconProps>> 'IxInnerPropTypes' and' IxPublicPropTypes' are defined in https://github.com/IDuxFE/idux/blob/main/packages/cdk/utils/src/props.ts#L54 the type of the icon component is defined in https://github.com/IDuxFE/idux/blob/main/packages/components/icon/src/types.ts |
Version
3.2.19
Reproduction link
Steps to reproduce
What is expected?
What is actually happening?
Type 'number' is not assignable to type 'NumberConstructor'.
The text was updated successfully, but these errors were encountered: