mirror of https://github.com/vuejs/core.git
parent
a41c5f1f43
commit
4af85835f7
|
@ -1,4 +1,11 @@
|
||||||
import { computed, defineComponent, ref, shallowRef, watch } from 'vue'
|
import {
|
||||||
|
computed,
|
||||||
|
defineComponent,
|
||||||
|
defineModel,
|
||||||
|
ref,
|
||||||
|
shallowRef,
|
||||||
|
watch,
|
||||||
|
} from 'vue'
|
||||||
import { expectType } from './utils'
|
import { expectType } from './utils'
|
||||||
|
|
||||||
const source = ref('foo')
|
const source = ref('foo')
|
||||||
|
@ -106,3 +113,31 @@ defineComponent({
|
||||||
expectType<Steps>(value)
|
expectType<Steps>(value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// defineModel
|
||||||
|
const bool = defineModel({ default: false })
|
||||||
|
watch(bool, value => {
|
||||||
|
expectType<boolean>(value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const bool1 = defineModel<boolean>()
|
||||||
|
watch(bool1, value => {
|
||||||
|
expectType<boolean | undefined>(value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const msg = defineModel<string>({ required: true })
|
||||||
|
watch(msg, value => {
|
||||||
|
expectType<string>(value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const arr = defineModel<string[]>({ required: true })
|
||||||
|
watch(arr, value => {
|
||||||
|
expectType<string[]>(value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const obj = defineModel<{ foo: string }>({ required: true })
|
||||||
|
watch(obj, value => {
|
||||||
|
expectType<{ foo: string }>(value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -115,6 +115,13 @@ const INITIAL_WATCHER_VALUE = {}
|
||||||
|
|
||||||
type MultiWatchSources = (WatchSource<unknown> | object)[]
|
type MultiWatchSources = (WatchSource<unknown> | object)[]
|
||||||
|
|
||||||
|
// overload: single source + cb
|
||||||
|
export function watch<T, Immediate extends Readonly<boolean> = false>(
|
||||||
|
source: WatchSource<T>,
|
||||||
|
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
|
||||||
|
options?: WatchOptions<Immediate>,
|
||||||
|
): WatchStopHandle
|
||||||
|
|
||||||
// overload: array of multiple sources + cb
|
// overload: array of multiple sources + cb
|
||||||
export function watch<
|
export function watch<
|
||||||
T extends MultiWatchSources,
|
T extends MultiWatchSources,
|
||||||
|
@ -137,13 +144,6 @@ export function watch<
|
||||||
options?: WatchOptions<Immediate>,
|
options?: WatchOptions<Immediate>,
|
||||||
): WatchStopHandle
|
): WatchStopHandle
|
||||||
|
|
||||||
// overload: single source + cb
|
|
||||||
export function watch<T, Immediate extends Readonly<boolean> = false>(
|
|
||||||
source: WatchSource<T>,
|
|
||||||
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
|
|
||||||
options?: WatchOptions<Immediate>,
|
|
||||||
): WatchStopHandle
|
|
||||||
|
|
||||||
// overload: watching reactive object w/ cb
|
// overload: watching reactive object w/ cb
|
||||||
export function watch<
|
export function watch<
|
||||||
T extends object,
|
T extends object,
|
||||||
|
|
Loading…
Reference in New Issue