2020-04-04 00:05:52 +08:00
|
|
|
import { expectError, expectType } from 'tsd'
|
|
|
|
import { FunctionalComponent } from './index'
|
|
|
|
|
|
|
|
// simple function signature
|
|
|
|
const Foo = (props: { foo: number }) => props.foo
|
|
|
|
|
|
|
|
// TSX
|
|
|
|
expectType<JSX.Element>(<Foo foo={1} />)
|
2020-04-04 07:08:17 +08:00
|
|
|
// expectError(<Foo />) // tsd does not catch missing type errors
|
2020-04-04 00:05:52 +08:00
|
|
|
expectError(<Foo foo="bar" />)
|
2020-04-04 07:08:17 +08:00
|
|
|
expectError(<Foo baz="bar" />)
|
2020-04-04 00:05:52 +08:00
|
|
|
|
|
|
|
// Explicit signature with props + emits
|
|
|
|
const Bar: FunctionalComponent<
|
|
|
|
{ foo: number },
|
|
|
|
{ update: (value: number) => void }
|
|
|
|
> = (props, { emit }) => {
|
|
|
|
expectType<number>(props.foo)
|
|
|
|
|
|
|
|
emit('update', 123)
|
|
|
|
expectError(emit('nope'))
|
|
|
|
expectError(emit('update'))
|
|
|
|
expectError(emit('update', 'nope'))
|
|
|
|
}
|
|
|
|
|
|
|
|
// assigning runtime options
|
|
|
|
Bar.props = {
|
|
|
|
foo: Number
|
|
|
|
}
|
|
|
|
expectError((Bar.props = { foo: String }))
|
|
|
|
|
|
|
|
Bar.emits = {
|
|
|
|
update: value => value > 1
|
|
|
|
}
|
|
|
|
expectError((Bar.emits = { baz: () => void 0 }))
|
|
|
|
|
|
|
|
// TSX
|
|
|
|
expectType<JSX.Element>(<Bar foo={1} />)
|
2020-04-04 07:08:17 +08:00
|
|
|
// expectError(<Foo />) // tsd does not catch missing type errors
|
2020-04-04 00:05:52 +08:00
|
|
|
expectError(<Bar foo="bar" />)
|
2020-04-04 07:08:17 +08:00
|
|
|
expectError(<Foo baz="bar" />)
|