Skip to content

Commit 4c0f804

Browse files
committed
fix(types): infer setup attrs
1 parent 4376685 commit 4c0f804

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,33 @@ describe('define attrs', () => {
12451245
expectType<JSX.Element>(<MyComp bar={1} />)
12461246
})
12471247

1248-
test('define attrs w/ function component', () => {
1248+
test('define attrs w/ composition api', () => {
1249+
type CompAttrs = {
1250+
bar: number
1251+
baz?: string
1252+
}
1253+
const MyComp = defineComponent(
1254+
{
1255+
props: {
1256+
foo: {
1257+
type: String,
1258+
required: true
1259+
}
1260+
},
1261+
setup(props, { attrs }) {
1262+
expectType<string>(props.foo)
1263+
expectType<number>(attrs.bar)
1264+
expectType<string | undefined>(attrs.baz)
1265+
}
1266+
},
1267+
{
1268+
attrs: {} as CompAttrs
1269+
}
1270+
)
1271+
expectType<JSX.Element>(<MyComp foo="1" bar={1} />)
1272+
})
1273+
1274+
test('define attrs w/ functional component', () => {
12491275
type CompAttrs = {
12501276
bar: number
12511277
baz?: string

packages/runtime-core/src/componentOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export interface ComponentOptionsBase<
127127
>
128128
>
129129
>,
130-
ctx: SetupContext<E, S>
130+
ctx: SetupContext<E, S, Attrs>
131131
) => Promise<RawBindings> | RawBindings | RenderFunction | void
132132
name?: string
133133
template?: string | object // can be a direct DOM node

0 commit comments

Comments
 (0)