2019-12-22 23:58:12 +08:00
|
|
|
// TSX w/ defineComponent is tested in defineComponent.test-d.tsx
|
2020-06-09 22:17:42 +08:00
|
|
|
import {
|
|
|
|
KeepAlive,
|
|
|
|
Suspense,
|
|
|
|
Fragment,
|
|
|
|
Teleport,
|
|
|
|
expectError,
|
|
|
|
expectType
|
|
|
|
} from './index'
|
2019-11-05 07:38:55 +08:00
|
|
|
|
|
|
|
expectType<JSX.Element>(<div />)
|
|
|
|
expectType<JSX.Element>(<div id="foo" />)
|
|
|
|
expectType<JSX.Element>(<input value="foo" />)
|
|
|
|
|
2021-03-02 01:31:40 +08:00
|
|
|
// @ts-expect-error style css property validation
|
|
|
|
expectError(<div style={{ unknown: 123 }} />)
|
|
|
|
|
|
|
|
// allow array styles and nested array styles
|
|
|
|
expectType<JSX.Element>(<div style={[{ color: 'red' }]} />)
|
|
|
|
expectType<JSX.Element>(
|
|
|
|
<div style={[{ color: 'red' }, [{ fontSize: '1em' }]]} />
|
|
|
|
)
|
|
|
|
|
2020-06-09 22:17:42 +08:00
|
|
|
// @ts-expect-error unknown prop
|
2019-11-05 07:38:55 +08:00
|
|
|
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" />)
|
|
|
|
|
2020-04-02 10:04:55 +08:00
|
|
|
expectType<JSX.Element>(<Teleport to="#foo" />)
|
|
|
|
expectType<JSX.Element>(<Teleport to="#foo" key="1" />)
|
2020-06-09 22:17:42 +08:00
|
|
|
|
|
|
|
// @ts-expect-error
|
2020-04-02 10:04:55 +08:00
|
|
|
expectError(<Teleport />)
|
2020-06-09 22:17:42 +08:00
|
|
|
// @ts-expect-error
|
2020-04-02 10:04:55 +08:00
|
|
|
expectError(<Teleport to={1} />)
|
2019-11-05 07:38:55 +08:00
|
|
|
|
|
|
|
// KeepAlive
|
|
|
|
expectType<JSX.Element>(<KeepAlive include="foo" exclude={['a']} />)
|
2020-02-16 10:48:45 +08:00
|
|
|
expectType<JSX.Element>(<KeepAlive key="1" />)
|
2020-06-09 22:17:42 +08:00
|
|
|
// @ts-expect-error
|
2019-11-05 07:38:55 +08:00
|
|
|
expectError(<KeepAlive include={123} />)
|
|
|
|
|
|
|
|
// Suspense
|
|
|
|
expectType<JSX.Element>(<Suspense />)
|
2020-02-16 10:48:45 +08:00
|
|
|
expectType<JSX.Element>(<Suspense key="1" />)
|
2020-09-16 21:30:47 +08:00
|
|
|
expectType<JSX.Element>(
|
|
|
|
<Suspense onResolve={() => {}} onFallback={() => {}} onPending={() => {}} />
|
|
|
|
)
|
2020-06-09 22:17:42 +08:00
|
|
|
// @ts-expect-error
|
2019-11-05 07:38:55 +08:00
|
|
|
expectError(<Suspense onResolve={123} />)
|