Skip to content

Commit

Permalink
test(dts-test): extractProps tests already exist & improve them
Browse files Browse the repository at this point in the history
  • Loading branch information
DrJume committed Dec 5, 2023
1 parent 979b817 commit 3bd391f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
35 changes: 26 additions & 9 deletions packages/dts-test/extractProps.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ExtractPropTypes, ExtractPublicPropTypes } from 'vue'
import {
ExtractDefaultPropTypes,
ExtractPropTypes,
ExtractPublicPropTypes
} from 'vue'
import { expectType, Prettify } from './utils'

const propsOptions = {
Expand All @@ -16,15 +20,28 @@ const propsOptions = {
// internal facing props
declare const props: Prettify<ExtractPropTypes<typeof propsOptions>>

expectType<number>(props.foo)
expectType<string>(props.bar)
expectType<boolean>(props.baz)
expectType<unknown[] | undefined>(props.qux)
expectType<{
foo: number
bar: string
baz: boolean
qux: unknown[] | undefined
}>(props)

Check failure on line 28 in packages/dts-test/extractProps.test-d.ts

View workflow job for this annotation

GitHub Actions / lint-and-test-dts

Argument of type '{ readonly bar: string; readonly foo: 1; readonly baz: boolean; readonly qux?: unknown[] | undefined; }' is not assignable to parameter of type '{ foo: number; bar: string; baz: boolean; qux: unknown[] | undefined; }'.

// external facing props
declare const publicProps: Prettify<ExtractPublicPropTypes<typeof propsOptions>>

expectType<number | undefined>(publicProps.foo)
expectType<string>(publicProps.bar)
expectType<boolean | undefined>(publicProps.baz)
expectType<unknown[] | undefined>(publicProps.qux)
expectType<{
foo?: number | undefined
bar: string
baz?: boolean | undefined
qux?: unknown[] | undefined
}>(publicProps)

// props with defaults
declare const propsWithDefaults: Prettify<
ExtractDefaultPropTypes<typeof propsOptions>
>
expectType<{
foo: number
baz: boolean
}>(propsWithDefaults)
18 changes: 2 additions & 16 deletions packages/dts-test/setupHelpers.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import {
VNode,
Ref,
defineModel,
toRefs,
ExtractPropTypes,
ExtractPublicPropTypes,
ExtractDefaultPropTypes
toRefs
} from 'vue'
import { Prettify, describe, expectType } from './utils'
import { describe, expectType } from './utils'
import { defineComponent } from 'vue'
import { useModel } from 'vue'

Expand Down Expand Up @@ -184,17 +181,6 @@ describe('defineProps w/ runtime declaration', () => {
bar: number
baz: unknown[]
}>(props)

Check failure on line 183 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>>)
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 Down

0 comments on commit 3bd391f

Please sign in to comment.