tsx.test-d.tsx 1.6 KB

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