un-pany/v3-admin-vite

打包失败

Closed this issue · 10 comments

复现 将下面代码粘到 login.vue 或者其他vue 文件中,运行 build 命令 会失败
`

Default
With shortcuts
<script lang="ts" setup> import { ref } from 'vue' const value1 = ref([ new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10), ]) const value2 = ref('') const shortcuts = [ { text: 'Last week', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 7) return [start, end] }, }, { text: 'Last month', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 30) return [start, end] }, }, { text: 'Last 3 months', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 90) return [start, end] }, }, ] </script> <style scoped> .block { padding: 30px 0; text-align: center; border-right: solid 1px var(--el-border-color); flex: 1; } .block:last-child { border-right: none; } .block .demonstration { display: block; color: var(--el-text-color-secondary); font-size: 14px; margin-bottom: 20px; } </style>

错误src/views/dashboard/index.vue:5:7 - error TS2322: Type '{ toString: () => string; toDateString: () => string; toTimeString: () => string; toLocaleString: { (): string; (locales?: string | string[] | undefined, options?: DateTimeFormatOptions | undefined): string; (locales?: LocalesArgument, options?: DateTimeFormatOptions | undefined): string; }; ... 39 more ...; [Symbol...' is not assignable to type 'EpPropMergeType<(new (...args: any[]) => ModelValueType & {}) | (() => ModelValueType) | ((new (...args: any[]) => ModelValueType & {}) | (() => ModelValueType))[], unknown, unknown> | undefined'.
Type '{ toString: () => string; toDateString: () => string; toTimeString: () => string; toLocaleString: { (): string; (locales?: string | string[] | undefined, options?: DateTimeFormatOptions | undefined): string;
(locales?: LocalesArgument, options?: DateTimeFormatOptions | undefined): string; }; ... 39 more ...; [Symbol...' is not assignable to type '[DateModelType, DateModelType]'.
Target requires 2 element(s) but source may have fewer.

5 v-model="value1"
~~~~~~~`

你这应该是你业务代码的问题,多仔细检查检查

你这应该是你业务代码的问题,多仔细检查检查

作者你好,感谢回复, 我又试了一下 clone 了你的最新代码 然后 复制上面的代码覆盖了login.vue 还是一样的。上面的代码应该没有问题这是elemtuiPlus 的官方demo http://element-plus.org/zh-CN/component/datetime-picker.html#%E6%97%A5%E6%9C%9F%E6%97%B6%E9%97%B4%E6%A0%BC%E5%BC%8F

完整代码贴出来看看

完整代码贴出来看看

<template>
  <div class="block">
    <span class="demonstration">Default</span>
    <el-date-picker
      v-model="value1"
      type="datetimerange"
      range-separator="To"
      start-placeholder="Start date"
      end-placeholder="End date"
    />
  </div>
  <div class="block">
    <span class="demonstration">With shortcuts</span>
    <el-date-picker
      v-model="value2"
      type="datetimerange"
      :shortcuts="shortcuts"
      range-separator="To"
      start-placeholder="Start date"
      end-placeholder="End date"
    />
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const value1 = ref([
  new Date(2000, 10, 10, 10, 10),
  new Date(2000, 10, 11, 10, 10),
])
const value2 = ref('')

const shortcuts = [
  {
    text: 'Last week',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
      return [start, end]
    },
  },
  {
    text: 'Last month',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      return [start, end]
    },
  },
  {
    text: 'Last 3 months',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
      return [start, end]
    },
  },
]
</script>
<style scoped>
.block {
  padding: 30px 0;
  text-align: center;
  border-right: solid 1px var(--el-border-color);
  flex: 1;
}
.block:last-child {
  border-right: none;
}
.block .demonstration {
  display: block;
  color: var(--el-text-color-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}
</style>

value1 的类型错了

稍等,你的代码好像没有问题

这似乎是 Element Plus 的问题,等待它的新版修复这个问题吧,目前的话可以暂时将类型断言为 any

这似乎是 Element Plus 的问题,等待它的新版修复这个问题吧,目前的话可以暂时将类型断言为 any

好的 感谢回复

as ModelValueType 断言为 Element Plus 自带的 ModelValueType 类型比较准确

as ModelValueType 断言为 Element Plus 自带的 ModelValueType 类型比较准确

好的 多谢回复