Repository: youzan/vant
File: packages/vant/src/time-picker/TimePicker.tsx (TypeScript)

Code before:
  TimePickerExpose
>;

export default defineComponent({
  name,

  props: timePickerProps,

  emits: ['confirm', 'cancel', 'change', 'update:modelValue'],

  setup(props, { emit, slots }) {
    const currentValues = ref<string[]>(props.modelValue);
    const pickerRef = ref<PickerInstance>();

    const getValidTime = (time: string) => {
      const timeLimitArr = time.split(':');
      return fullColumns.map((col, i) =>
        props.columnsType.includes(col) ? timeLimitArr[i] : '00',
      );
    };

    const confirm = () => {
      return pickerRef.value?.confirm();
    };

    const getSelectedTime = (): Array<string> => {
      return currentValues.value;
    };

    const columns = computed(() => {
      let { minHour, maxHour, minMinute, maxMinute, minSecond, maxSecond } =
        props;

      if (props.minTime || props.maxTime) {
        const fullTime: Record<TimePickerColumnType, string | number> = {
          hour: 0,
          minute: 0,
          second: 0,
        };
        props.columnsType.forEach((col, i) => {
          fullTime[col] = currentValues.value[i] ?? 0;
        });
        const { hour, minute } = fullTime;
        if (props.minTime) {
          const [minH, minM, minS] = getValidTime(props.minTime);
          minHour = minH;
          minMinute = +hour <= +minHour ? minM : '00';
          minSecond = +hour <= +minHour && +minute <= +minMinute ? minS : '00';
        }
        if (props.maxTime) {
          const [maxH, maxM, maxS] = getValidTime(props.maxTime);

Review comment (suggestion):
```suggestion
    const getSelectedTime = (): string[] => {
```

Code after:
export type TimePickerInstance = ComponentPublicInstance<
  TimePickerProps,
  TimePickerExpose
>;

export default defineComponent({
  name,

  props: timePickerProps,

  emits: ['confirm', 'cancel', 'change', 'update:modelValue'],

  setup(props, { emit, slots }) {
    const currentValues = ref<string[]>(props.modelValue);
    const pickerRef = ref<PickerInstance>();

    const getValidTime = (time: string) => {
      const timeLimitArr = time.split(':');
      return fullColumns.map((col, i) =>
        props.columnsType.includes(col) ? timeLimitArr[i] : '00',
      );
    };

    const confirm = () => {
      return pickerRef.value?.confirm();
    };

    const getSelectedTime = (): string[] => {
      return currentValues.value;
    };

    const columns = computed(() => {
      let { minHour, maxHour, minMinute, maxMinute, minSecond, maxSecond } =
        props;

      if (props.minTime || props.maxTime) {
        const fullTime: Record<TimePickerColumnType, string | number> = {
          hour: 0,
          minute: 0,
          second: 0,
        };
        props.columnsType.forEach((col, i) => {
          fullTime[col] = currentValues.value[i] ?? 0;
        });
        const { hour, minute } = fullTime;
        if (props.minTime) {
          const [minH, minM, minS] = getValidTime(props.minTime);
          minHour = minH;
          minMinute = +hour <= +minHour ? minM : '00';
          minSecond = +hour <= +minHour && +minute <= +minMinute ? minS : '00';
        }