import { type ComponentInstance, type ComponentPublicInstance, type FunctionalComponent, defineComponent, ref, } from 'vue' import { describe, expectType } from './utils' describe('defineComponent', () => { const CompSetup = defineComponent({ props: { test: String, }, setup() { return { a: 1, } }, }) const compSetup: ComponentInstance = {} as any expectType(compSetup.test) expectType(compSetup.a) expectType(compSetup) }) describe('functional component', () => { // Functional const CompFunctional: FunctionalComponent<{ test?: string }> = {} as any const compFunctional: ComponentInstance = {} as any expectType(compFunctional.test) expectType(compFunctional) const CompFunction: (props: { test?: string }) => any = {} as any const compFunction: ComponentInstance = {} as any expectType(compFunction.test) expectType(compFunction) }) describe('options component', () => { // Options const CompOptions = defineComponent({ props: { test: String, }, data() { return { a: 1, } }, computed: { b() { return 'test' }, }, methods: { func(a: string) { return true }, }, }) const compOptions: ComponentInstance = {} as any expectType(compOptions.test) expectType(compOptions.a) expectType<(a: string) => boolean>(compOptions.func) expectType(compOptions) }) describe('object no defineComponent', () => { // object - no defineComponent const CompObjectSetup = { props: { test: String, }, setup() { return { a: 1, } }, } const compObjectSetup: ComponentInstance = {} as any expectType(compObjectSetup.test) expectType(compObjectSetup.a) expectType(compObjectSetup) const CompObjectData = { props: { test: String, }, data() { return { a: 1, } }, } const compObjectData: ComponentInstance = {} as any expectType(compObjectData.test) expectType(compObjectData.a) expectType(compObjectData) const CompObjectNoProps = { data() { return { a: 1, } }, } const compObjectNoProps: ComponentInstance = {} as any expectType(compObjectNoProps.test) expectType(compObjectNoProps.a) expectType(compObjectNoProps) }) describe('Generic component', () => { const Comp = defineComponent( // TODO: babel plugin to auto infer runtime props options from type // similar to defineProps<{...}>() (props: { msg: T; list: T[] }) => { // use Composition API here like in