extractProps.test-d.ts 791 B

123456789101112131415161718192021222324252627282930
  1. import type { ExtractPropTypes, ExtractPublicPropTypes } from 'vue'
  2. import { type Prettify, expectType } from './utils'
  3. const propsOptions = {
  4. foo: {
  5. default: 1,
  6. },
  7. bar: {
  8. type: String,
  9. required: true,
  10. },
  11. baz: Boolean,
  12. qux: Array,
  13. } as const
  14. // internal facing props
  15. declare const props: Prettify<ExtractPropTypes<typeof propsOptions>>
  16. expectType<number>(props.foo)
  17. expectType<string>(props.bar)
  18. expectType<boolean>(props.baz)
  19. expectType<unknown[] | undefined>(props.qux)
  20. // external facing props
  21. declare const publicProps: Prettify<ExtractPublicPropTypes<typeof propsOptions>>
  22. expectType<number | undefined>(publicProps.foo)
  23. expectType<string>(publicProps.bar)
  24. expectType<boolean | undefined>(publicProps.baz)
  25. expectType<unknown[] | undefined>(publicProps.qux)