Home / File/ watch-test.ts — vue Source File

watch-test.ts — vue Source File

Architecture documentation for watch-test.ts, a typescript file in the vue codebase. 4 imports, 0 dependents.

File typescript CompilerSFC StyleProcessor 4 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  1df81a90_dbd2_5824_ac70_5e073a1e5c40["watch-test.ts"]
  09422b63_6947_479f_f3b8_a48790187388["./index"]
  1df81a90_dbd2_5824_ac70_5e073a1e5c40 --> 09422b63_6947_479f_f3b8_a48790187388
  640c5630_c924_297a_b265_64ad36b365b4["utils.ts"]
  1df81a90_dbd2_5824_ac70_5e073a1e5c40 --> 640c5630_c924_297a_b265_64ad36b365b4
  526bbcde_5613_9f1a_1c80_ab1e7061c667["expectType"]
  1df81a90_dbd2_5824_ac70_5e073a1e5c40 --> 526bbcde_5613_9f1a_1c80_ab1e7061c667
  ae6eb6a4_c3be_68e2_81f6_f67b97a4ccd3["expectType"]
  1df81a90_dbd2_5824_ac70_5e073a1e5c40 --> ae6eb6a4_c3be_68e2_81f6_f67b97a4ccd3
  style 1df81a90_dbd2_5824_ac70_5e073a1e5c40 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { ref, computed, watch, shallowRef } from '../../index'
import { expectType } from '../utils'

const source = ref('foo')
const source2 = computed(() => source.value)
const source3 = () => 1

// lazy watcher will have consistent types for oldValue.
watch(source, (value, oldValue) => {
  expectType<string>(value)
  expectType<string>(oldValue)
})

watch([source, source2, source3], (values, oldValues) => {
  expectType<[string, string, number]>(values)
  expectType<[string, string, number]>(oldValues)
})

// const array
watch([source, source2, source3] as const, (values, oldValues) => {
  expectType<Readonly<[string, string, number]>>(values)
  expectType<Readonly<[string, string, number]>>(oldValues)
})

// immediate watcher's oldValue will be undefined on first run.
watch(
  source,
  (value, oldValue) => {
    expectType<string>(value)
    expectType<string | undefined>(oldValue)
  },
  { immediate: true }
)

watch(
  [source, source2, source3],
  (values, oldValues) => {
    expectType<[string, string, number]>(values)
    expectType<[string | undefined, string | undefined, number | undefined]>(
      oldValues
    )
  },
  { immediate: true }
)

// const array
watch(
  [source, source2, source3] as const,
  (values, oldValues) => {
    expectType<Readonly<[string, string, number]>>(values)
    expectType<
      Readonly<[string | undefined, string | undefined, number | undefined]>
    >(oldValues)
  },
  { immediate: true }
)

// should provide correct ref.value inner type to callbacks
const nestedRefSource = ref({
  foo: ref(1)
})

watch(nestedRefSource, (v, ov) => {
  expectType<{ foo: number }>(v)
  expectType<{ foo: number }>(ov)
})

const someRef = ref({ test: 'test' })
const otherRef = ref({ a: 'b' })
watch([someRef, otherRef], values => {
  const value1 = values[0]
  // no type error
  console.log(value1.test)

  const value2 = values[1]
  // no type error
  console.log(value2.a)
})

{
  //#12978
  type Steps = { step: '1' } | { step: '2' }
  const shallowUnionGenParam = shallowRef<Steps>({ step: '1' })
  const shallowUnionAsCast = shallowRef({ step: '1' } as Steps)

  watch(shallowUnionGenParam, value => {
    expectType<Steps>(value)
  })
  watch(shallowUnionAsCast, value => {
    expectType<Steps>(value)
  })
}

Domain

Subdomains

Functions

Types

Dependencies

Frequently Asked Questions

What does watch-test.ts do?
watch-test.ts is a source file in the vue codebase, written in typescript. It belongs to the CompilerSFC domain, StyleProcessor subdomain.
What functions are defined in watch-test.ts?
watch-test.ts defines 2 function(s): source2, source3.
What does watch-test.ts depend on?
watch-test.ts imports 4 module(s): ./index, expectType, expectType, utils.ts.
Where is watch-test.ts in the architecture?
watch-test.ts is located at types/test/v3/watch-test.ts (domain: CompilerSFC, subdomain: StyleProcessor, directory: types/test/v3).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free