Skip to content

Commit 9c2916a

Browse files
committed
fix: test when volar plugin is on
1 parent f8288c1 commit 9c2916a

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

packages/dts-test/defineComponent.test-d.tsx

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
SlotsType,
1313
AttrsType,
1414
Slots,
15-
VNode
15+
VNode,
16+
ImgHTMLAttributes,
17+
StyleValue
1618
} from 'vue'
1719
import { describe, expectType, IsUnion, test } from './utils'
1820

@@ -1325,22 +1327,45 @@ describe('define attrs', () => {
13251327
expectType<JSX.Element>(<MyComp foo="1" bar={1} />)
13261328
})
13271329

1328-
test('default attrs like class, style', () => {
1329-
const MyComp = defineComponent({
1330+
test('wrap elements, such as img element (Keep the volar plugin open)', () => {
1331+
const MyImg = defineComponent({
13301332
props: {
13311333
foo: String
13321334
},
1333-
attrs: Object as AttrsType<{
1334-
bar?: number
1335-
}>,
1335+
attrs: Object as AttrsType<ImgHTMLAttributes>,
13361336
created() {
1337-
expectType<number | undefined>(this.$attrs.bar)
1338-
expectType<unknown>(this.$attrs.class)
1339-
expectType<unknown>(this.$attrs.style)
1337+
expectType<any>(this.$attrs.class)
1338+
expectType<StyleValue | undefined>(this.$attrs.style)
1339+
},
1340+
render() {
1341+
return <img {...this.$attrs} />
1342+
}
1343+
})
1344+
expectType<JSX.Element>(<MyImg class={'str'} style={'str'} src={'str'} />)
1345+
})
1346+
1347+
test('secondary packaging of components', () => {
1348+
const childProps = {
1349+
foo: String
1350+
}
1351+
type ChildProps = ExtractPropTypes<typeof childProps>
1352+
const Child = defineComponent({
1353+
props: childProps,
1354+
render() {
1355+
return <div>{this.foo}</div>
1356+
}
1357+
})
1358+
const Comp = defineComponent({
1359+
props: {
1360+
bar: Number
1361+
},
1362+
attrs: Object as AttrsType<ChildProps>,
1363+
render() {
1364+
return <Child {...this.$attrs} />
13401365
}
13411366
})
13421367
expectType<JSX.Element>(
1343-
<MyComp class={'str'} style={'str'} foo="1" bar={1} />
1368+
<Comp class={'str'} style={'str'} bar={1} foo={'str'} />
13441369
)
13451370
})
13461371
})

packages/runtime-core/src/componentPublicInstance.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
AllowedComponentProps,
32
ComponentInternalInstance,
43
Data,
54
noAttrsDefine,
@@ -225,8 +224,7 @@ export type ComponentPublicInstance<
225224
>
226225
$attrs: noAttrsDefine<Attrs> extends true
227226
? Data
228-
: Omit<UnwrapAttrsType<Attrs>, keyof (P & PublicProps)> &
229-
AllowedComponentProps
227+
: Omit<UnwrapAttrsType<Attrs>, keyof (P & PublicProps)>
230228
$refs: Data
231229
$slots: UnwrapSlotsType<S>
232230
$root: ComponentPublicInstance | null

0 commit comments

Comments
 (0)