Home / Function/ plainType() — vue Function Reference

plainType() — vue Function Reference

Architecture documentation for the plainType() function in reactivity-test.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  d5c31c1f_5bf1_8cae_419f_310d4b9998ab["plainType()"]
  b4eae887_aae6_b3d1_59a1_c048a1e8c568["reactivity-test.ts"]
  d5c31c1f_5bf1_8cae_419f_310d4b9998ab -->|defined in| b4eae887_aae6_b3d1_59a1_c048a1e8c568
  style d5c31c1f_5bf1_8cae_419f_310d4b9998ab fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

types/test/v3/reactivity-test.ts lines 20–77

function plainType(arg: number | Ref<number>) {
  // ref coercing
  const coerced = ref(arg)
  expectType<Ref<number>>(coerced)

  // isRef as type guard
  if (isRef(arg)) {
    expectType<Ref<number>>(arg)
  }

  // ref unwrapping
  expectType<number>(unref(arg))

  // ref inner type should be unwrapped
  const nestedRef = ref({
    foo: ref(1)
  })
  expectType<{ foo: number }>(nestedRef.value)

  // ref boolean
  const falseRef = ref(false)
  expectType<Ref<boolean>>(falseRef)
  expectType<boolean>(falseRef.value)

  // ref true
  const trueRef = ref<true>(true)
  expectType<Ref<true>>(trueRef)
  expectType<true>(trueRef.value)

  // tuple
  expectType<[number, string]>(unref(ref([1, '1'])))

  interface IteratorFoo {
    [Symbol.iterator]: any
  }

  // with symbol
  expectType<Ref<IteratorFoo | null | undefined>>(
    ref<IteratorFoo | null | undefined>()
  )

  // should not unwrap ref inside arrays
  const arr = ref([1, new Map<string, any>(), ref('1')]).value
  const value = arr[0]
  if (isRef(value)) {
    expectType<Ref>(value)
  } else if (typeof value === 'number') {
    expectType<number>(value)
  } else {
    // should narrow down to Map type
    // and not contain any Ref type
    expectType<Map<string, any>>(value)
  }

  // should still unwrap in objects nested in arrays
  const arr2 = ref([{ a: ref(1) }]).value
  expectType<number>(arr2[0].a)
}

Domain

Subdomains

Frequently Asked Questions

What does plainType() do?
plainType() is a function in the vue codebase, defined in types/test/v3/reactivity-test.ts.
Where is plainType() defined?
plainType() is defined in types/test/v3/reactivity-test.ts at line 20.

Analyze Your Own Codebase

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

Try Supermodel Free