vue3-yuanma/test-dts/tsx.test-d.tsx

45 lines
1.3 KiB
TypeScript
Raw Normal View History

// TSX w/ defineComponent is tested in defineComponent.test-d.tsx
import { expectError, expectType } from 'tsd'
import { KeepAlive, Suspense, Fragment, Portal } from '@vue/runtime-dom'
expectType<JSX.Element>(<div />)
expectType<JSX.Element>(<div id="foo" />)
expectType<JSX.Element>(<input value="foo" />)
// unknown prop
expectError(<div foo="bar" />)
// allow key/ref on arbitrary element
expectType<JSX.Element>(<div key="foo" />)
expectType<JSX.Element>(<div ref="bar" />)
expectType<JSX.Element>(
<input
onInput={e => {
// infer correct event type
expectType<EventTarget | null>(e.target)
}}
/>
)
// built-in types
expectType<JSX.Element>(<Fragment />)
expectType<JSX.Element>(<Fragment key="1" />)
expectType<JSX.Element>(<Portal target="#foo" />)
2020-02-16 10:48:45 +08:00
expectType<JSX.Element>(<Portal target="#foo" key="1" />)
expectError(<Portal />)
2020-02-16 10:48:45 +08:00
expectError(<Portal target={1} />)
// KeepAlive
expectType<JSX.Element>(<KeepAlive include="foo" exclude={['a']} />)
2020-02-16 10:48:45 +08:00
expectType<JSX.Element>(<KeepAlive key="1" />)
expectError(<KeepAlive include={123} />)
// Suspense
expectType<JSX.Element>(<Suspense />)
2020-02-16 10:48:45 +08:00
expectType<JSX.Element>(<Suspense key="1" />)
expectType<JSX.Element>(<Suspense onResolve={() => {}} onRecede={() => {}} />)
expectError(<Suspense onResolve={123} />)