Skip to content

Commit 0c7fd13

Browse files
authored
fix(types): fix typescript error when spreading $props(#5968)
1 parent 8071ef4 commit 0c7fd13

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

Diff for: packages/runtime-core/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export { h } from './h'
8686
// Advanced render function utilities
8787
export { createVNode, cloneVNode, mergeProps, isVNode } from './vnode'
8888
// VNode types
89-
export { Fragment, Text, Comment, Static } from './vnode'
89+
export { Fragment, Text, Comment, Static, VNodeRef } from './vnode'
9090
// Built-in components
9191
export { Teleport, TeleportProps } from './components/Teleport'
9292
export { Suspense, SuspenseProps } from './components/Suspense'

Diff for: packages/runtime-core/src/vnode.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { convertLegacyComponent } from './compat/component'
4343
import { convertLegacyVModelProps } from './compat/componentVModel'
4444
import { defineLegacyVNodeProperties } from './compat/renderFn'
4545
import { callWithAsyncErrorHandling, ErrorCodes } from './errorHandling'
46+
import { ComponentPublicInstance } from './componentPublicInstance'
4647

4748
export const Fragment = Symbol(__DEV__ ? 'Fragment' : undefined) as any as {
4849
__isFragment: true
@@ -68,7 +69,10 @@ export type VNodeTypes =
6869
export type VNodeRef =
6970
| string
7071
| Ref
71-
| ((ref: object | null, refs: Record<string, any>) => void)
72+
| ((
73+
ref: Element | ComponentPublicInstance | null,
74+
refs: Record<string, any>
75+
) => void)
7276

7377
export type VNodeNormalizedRefAtom = {
7478
i: ComponentInternalInstance

Diff for: packages/runtime-dom/types/jsx.d.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export interface CSSProperties
4040
* For examples and more information, visit:
4141
* https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors
4242
*/
43-
4443
[v: `--${string}`]: string | number | undefined
4544
}
4645

@@ -1311,10 +1310,7 @@ import * as RuntimeCore from '@vue/runtime-core'
13111310

13121311
type ReservedProps = {
13131312
key?: string | number | symbol
1314-
ref?:
1315-
| string
1316-
| RuntimeCore.Ref
1317-
| ((ref: Element | RuntimeCore.ComponentPublicInstance | null) => void)
1313+
ref?: RuntimeCore.VNodeRef
13181314
ref_for?: boolean
13191315
ref_key?: string
13201316
}

Diff for: test-dts/componentTypeExtensions.test-d.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const Custom = defineComponent({
4444
expectType<JSX.Element>(<Custom baz={1} />)
4545
expectType<JSX.Element>(<Custom custom={1} baz={1} />)
4646
expectType<JSX.Element>(<Custom bar="bar" baz={1} />)
47+
expectType<JSX.Element>(<Custom ref={''} bar="bar" baz={1} />)
4748

4849
// @ts-expect-error
4950
expectType<JSX.Element>(<Custom />)

Diff for: test-dts/defineComponent.test-d.tsx

+19
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,25 @@ describe('DefineComponent should infer correct types when assigning to Component
11441144
expectType<Component>(component)
11451145
})
11461146

1147+
// #5969
1148+
describe('should allow to assign props', () => {
1149+
const Child = defineComponent({
1150+
props: {
1151+
bar: String
1152+
}
1153+
})
1154+
1155+
const Parent = defineComponent({
1156+
props: {
1157+
...Child.props,
1158+
foo: String
1159+
}
1160+
})
1161+
1162+
const child = new Child()
1163+
expectType<JSX.Element>(<Parent {...child.$props} />)
1164+
})
1165+
11471166
// check if defineComponent can be exported
11481167
export default {
11491168
// function components

0 commit comments

Comments
 (0)