Skip to content

Commit 979b817

Browse files
committed
test(types/defineProps): add failing runtime declaration tests to align with type declaration
* add tests for Extract*PropTypes ref: vuejs#6421
1 parent af909b7 commit 979b817

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

packages/dts-test/setupHelpers.test-d.ts

+22-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import {
99
VNode,
1010
Ref,
1111
defineModel,
12-
toRefs
12+
toRefs,
13+
ExtractPropTypes,
14+
ExtractPublicPropTypes,
15+
ExtractDefaultPropTypes
1316
} from 'vue'
14-
import { describe, expectType } from './utils'
17+
import { Prettify, describe, expectType } from './utils'
1518
import { defineComponent } from 'vue'
1619
import { useModel } from 'vue'
1720

@@ -164,7 +167,7 @@ describe('withDefaults w/ boolean type', () => {
164167

165168
describe('defineProps w/ runtime declaration', () => {
166169
// runtime declaration
167-
const props = defineProps({
170+
const propOptions = {
168171
foo: String,
169172
bar: {
170173
type: Number,
@@ -174,12 +177,24 @@ describe('defineProps w/ runtime declaration', () => {
174177
type: Array,
175178
required: true
176179
}
177-
})
180+
} as const
181+
const props = defineProps(propOptions)
178182
expectType<{
179-
foo?: string
183+
foo: string | undefined
180184
bar: number
181185
baz: unknown[]
182186
}>(props)
187+
expectType<{
188+
foo: string | undefined
189+
bar: number
190+
baz: unknown[]
191+
}>({} as Prettify<ExtractPropTypes<typeof propOptions>>)
192+
expectType<{
193+
foo?: string | undefined
194+
bar?: number | undefined
195+
baz: unknown[]
196+
}>({} as Prettify<ExtractPublicPropTypes<typeof propOptions>>)
197+
expectType<{ bar: number }>({} as ExtractDefaultPropTypes<typeof propOptions>)
183198

184199
props.foo && props.foo + 'bar'
185200
props.bar + 1
@@ -191,6 +206,8 @@ describe('defineProps w/ runtime declaration', () => {
191206
props2.foo + props2.bar
192207
// @ts-expect-error
193208
props2.baz
209+
210+
expectType<Ref<string | undefined>>(toRefs(props).foo)
194211
})
195212

196213
describe('defineEmits w/ type declaration', () => {

0 commit comments

Comments
 (0)