fix(calendar): on-update:value prop type

This commit is contained in:
07akioni 2021-06-12 19:23:05 +08:00
parent 7033bf9272
commit 5a7b2fa0e2
5 changed files with 44 additions and 12 deletions

View File

@ -1,5 +1,11 @@
# CHANGELOG
## Pending
### Fixes
- Fix `n-calendar`'s `on-update:value` prop type.
## 2.11.7
### Fixes

View File

@ -1,5 +1,11 @@
# CHANGELOG
## Pending
### Fixes
- 修复 `n-calendar``on-update:value` 属性类型
## 2.11.7
### Fixes

View File

@ -21,6 +21,7 @@ import { useConfig, useLocale, useTheme } from '../../_mixins'
import type { ThemeProps } from '../../_mixins'
import { calendarLight } from '../styles'
import type { CalendarTheme } from '../styles'
import type { OnUpdateValue, DateItem } from './interface'
import style from './styles/index.cssr'
const calendarProps = {
@ -31,22 +32,12 @@ const calendarProps = {
type: Number as PropType<number | null>,
defualt: null
},
'onUpdate:value': [Function, Array] as PropType<
MaybeArray<(value: number) => void>
>,
onUpdateValue: [Function, Array] as PropType<
MaybeArray<(value: number) => void>
>
'onUpdate:value': [Function, Array] as PropType<MaybeArray<OnUpdateValue>>,
onUpdateValue: [Function, Array] as PropType<MaybeArray<OnUpdateValue>>
} as const
export type CalendarProps = ExtractPublicPropTypes<typeof calendarProps>
interface DateItem {
year: number
month: number
date: number
}
export default defineComponent({
name: 'Calendar',
props: calendarProps,
@ -78,6 +69,7 @@ export default defineComponent({
if (_onUpdateValue) {
call(_onUpdateValue, value, time)
}
console.log(time)
uncontrolledValueRef.value = value
}

View File

@ -0,0 +1,7 @@
export type OnUpdateValue = (value: number, time: DateItem) => void
export interface DateItem {
year: number
month: number
date: number
}

View File

@ -0,0 +1,21 @@
import { h } from 'vue'
import { mount } from '@vue/test-utils'
import { NCalendar } from '../index'
describe('n-button', () => {
it('should work with import on demand', () => {
mount(NCalendar)
})
it('props.onUpdate has correct type', () => {
;<NCalendar
onUpdateValue={(
value: number,
time: {
date: number
month: number
year: number
}
) => {}}
/>
})
})