Skip to content

Commit

Permalink
test(types/defineProps): add failing runtime declaration tests to ali…
Browse files Browse the repository at this point in the history
…gn with type declaration

* add tests for Extract*PropTypes

ref: vuejs#6421
  • Loading branch information
DrJume committed Dec 5, 2023
1 parent af909b7 commit 979b817
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions packages/dts-test/setupHelpers.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import {
VNode,
Ref,
defineModel,
toRefs
toRefs,
ExtractPropTypes,
ExtractPublicPropTypes,
ExtractDefaultPropTypes
} from 'vue'
import { describe, expectType } from './utils'
import { Prettify, describe, expectType } from './utils'
import { defineComponent } from 'vue'
import { useModel } from 'vue'

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

describe('defineProps w/ runtime declaration', () => {
// runtime declaration
const props = defineProps({
const propOptions = {
foo: String,
bar: {
type: Number,
Expand All @@ -174,12 +177,24 @@ describe('defineProps w/ runtime declaration', () => {
type: Array,
required: true
}
})
} as const
const props = defineProps(propOptions)
expectType<{
foo?: string
foo: string | undefined
bar: number
baz: unknown[]
}>(props)

Check failure on line 186 in packages/dts-test/setupHelpers.test-d.ts

View workflow job for this annotation

GitHub Actions / lint-and-test-dts

Argument of type '{ readonly bar: number; readonly baz: unknown[]; readonly foo?: string | undefined; }' is not assignable to parameter of type '{ foo: string | undefined; bar: number; baz: unknown[]; }'.
expectType<{
foo: string | undefined
bar: number
baz: unknown[]
}>({} as Prettify<ExtractPropTypes<typeof propOptions>>)

Check failure on line 191 in packages/dts-test/setupHelpers.test-d.ts

View workflow job for this annotation

GitHub Actions / lint-and-test-dts

Argument of type '{ readonly bar: number; readonly baz: unknown[]; readonly foo?: string | undefined; }' is not assignable to parameter of type '{ foo: string | undefined; bar: number; baz: unknown[]; }'.
expectType<{
foo?: string | undefined
bar?: number | undefined
baz: unknown[]
}>({} as Prettify<ExtractPublicPropTypes<typeof propOptions>>)
expectType<{ bar: number }>({} as ExtractDefaultPropTypes<typeof propOptions>)

props.foo && props.foo + 'bar'
props.bar + 1
Expand All @@ -191,6 +206,8 @@ describe('defineProps w/ runtime declaration', () => {
props2.foo + props2.bar
// @ts-expect-error
props2.baz

expectType<Ref<string | undefined>>(toRefs(props).foo)

Check failure on line 210 in packages/dts-test/setupHelpers.test-d.ts

View workflow job for this annotation

GitHub Actions / lint-and-test-dts

Argument of type 'Ref<string | undefined> | undefined' is not assignable to parameter of type 'Ref<string | undefined>'.
})

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

0 comments on commit 979b817

Please sign in to comment.