tsx.test-d.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // TSX w/ defineComponent is tested in defineComponent.test-d.tsx
  2. import { KeepAlive, Suspense, Fragment, Teleport, VNode } from 'vue'
  3. import { expectType } from './utils'
  4. expectType<VNode>(<div />)
  5. expectType<JSX.Element>(<div />)
  6. expectType<JSX.Element>(<div id="foo" />)
  7. expectType<JSX.Element>(<input value="foo" />)
  8. // @ts-expect-error style css property validation
  9. ;<div style={{ unknown: 123 }} />
  10. // allow array styles and nested array styles
  11. expectType<JSX.Element>(<div style={[{ color: 'red' }]} />)
  12. expectType<JSX.Element>(
  13. <div style={[{ color: 'red' }, [{ fontSize: '1em' }]]} />
  14. )
  15. // @ts-expect-error unknown prop
  16. ;<div foo="bar" />
  17. // allow key/ref on arbitrary element
  18. expectType<JSX.Element>(<div key="foo" />)
  19. expectType<JSX.Element>(<div ref="bar" />)
  20. expectType<JSX.Element>(
  21. <input
  22. onInput={e => {
  23. // infer correct event type
  24. expectType<EventTarget | null>(e.target)
  25. }}
  26. />
  27. )
  28. // built-in types
  29. expectType<JSX.Element>(<Fragment />)
  30. expectType<JSX.Element>(<Fragment key="1" />)
  31. expectType<JSX.Element>(<Teleport to="#foo" />)
  32. expectType<JSX.Element>(<Teleport to="#foo" key="1" />)
  33. // @ts-expect-error
  34. ;<Teleport />
  35. // @ts-expect-error
  36. ;<Teleport to={1} />
  37. // KeepAlive
  38. expectType<JSX.Element>(<KeepAlive include="foo" exclude={['a']} />)
  39. expectType<JSX.Element>(<KeepAlive key="1" />)
  40. // @ts-expect-error
  41. ;<KeepAlive include={123} />
  42. // Suspense
  43. expectType<JSX.Element>(<Suspense />)
  44. expectType<JSX.Element>(<Suspense key="1" />)
  45. expectType<JSX.Element>(
  46. <Suspense onResolve={() => {}} onFallback={() => {}} onPending={() => {}} />
  47. )
  48. // @ts-expect-error
  49. ;<Suspense onResolve={123} />