types(Checkbox): add CheckboxInstance type (#9140)

This commit is contained in:
neverland
2021-07-28 17:37:08 +08:00
committed by GitHub
parent 51b7a66913
commit 4dd03edf76
4 changed files with 60 additions and 5 deletions
+33 -5
View File
@@ -1,4 +1,11 @@
import { computed, watch, defineComponent } from 'vue';
import {
watch,
computed,
ComputedRef,
defineComponent,
ExtractPropTypes,
ComponentPublicInstance,
} from 'vue';
// Utils
import { createNamespace, extend, pick, truthProp } from '../utils';
@@ -14,12 +21,33 @@ import Checker, { checkerProps } from './Checker';
const [name, bem] = createNamespace('checkbox');
const props = extend({}, checkerProps, {
bindGroup: truthProp,
});
type CheckboxProps = ExtractPropTypes<typeof props>;
type CheckboxExpose = {
toggle: (newValue?: boolean) => void;
/**
* @private
*/
props: CheckboxProps;
/**
* @private
*/
checked: ComputedRef<boolean>;
};
export type CheckboxInstance = ComponentPublicInstance<
CheckboxProps,
CheckboxExpose
>;
export default defineComponent({
name,
props: extend({}, checkerProps, {
bindGroup: truthProp,
}),
props,
emits: ['change', 'update:modelValue'],
@@ -74,7 +102,7 @@ export default defineComponent({
(value) => emit('change', value)
);
useExpose({ toggle, props, checked });
useExpose<CheckboxExpose>({ toggle, props, checked });
useLinkField(() => props.modelValue);
return () => (