Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(types): support inferring attrs #7444

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

Open
wants to merge 20 commits into
base: minor
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: wrapping functional components
  • Loading branch information
rudyxu1102 committed Oct 27, 2023
commit e2d4ec893e66085a303c461cbfa61d6daa290c6a
22 changes: 22 additions & 0 deletions 22 packages/dts-test/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,28 @@ describe('define attrs', () => {
/>
)
})

test('wrap components w/ functional component', () => {
const Child = defineComponent((props: { foo: string }, ctx) => {
return () => <div>{props.foo}</div>
})
const Comp = defineComponent({
props: {
bar: Number
},
attrs: Object as AttrsType<typeof Child>,
created() {
expectType<unknown>(this.$attrs.class)
expectType<unknown>(this.$attrs.style)
},
render() {
return <Child {...this.$attrs} />
}
})
expectType<JSX.Element>(
<Comp class={'str'} style={'str'} bar={1} foo={'str'} />
)
})
})

// #5948
Expand Down
9 changes: 5 additions & 4 deletions 9 packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ import {
ComponentPublicInstance,
isReservedPrefix,
IntersectionMixin,
UnwrapMixinsType,
ComponentPublicInstanceConstructor
UnwrapMixinsType
} from './componentPublicInstance'
import { warn } from './warning'
import { VNodeChild } from './vnode'
Expand Down Expand Up @@ -420,8 +419,10 @@ export type ComponentOptionsMixin = ComponentOptionsBase<

declare const AttrSymbol: unique symbol
export type AttrsType<T extends Record<string, any> = Record<string, any>> = {
[AttrSymbol]?: T extends ComponentPublicInstanceConstructor
? InstanceType<T>['$props']
[AttrSymbol]?: T extends new () => { $props: infer P }
? NonNullable<P>
: T extends (props: infer P, ...args: any) => any
? P
: T
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.