Home / Function/ inferRuntimeType() — vue Function Reference

inferRuntimeType() — vue Function Reference

Architecture documentation for the inferRuntimeType() function in compileScript.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  9315090e_2c5c_e529_e01a_651ebe7c77f0["inferRuntimeType()"]
  6c908c3e_1d62_cbed_b2a6_227a1d085a60["recordType()"]
  6c908c3e_1d62_cbed_b2a6_227a1d085a60 -->|calls| 9315090e_2c5c_e529_e01a_651ebe7c77f0
  507a306d_b939_d165_c13a_79d12a2665d9["extractRuntimeProps()"]
  507a306d_b939_d165_c13a_79d12a2665d9 -->|calls| 9315090e_2c5c_e529_e01a_651ebe7c77f0
  style 9315090e_2c5c_e529_e01a_651ebe7c77f0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/compiler-sfc/src/compileScript.ts lines 1469–1554

function inferRuntimeType(
  node: TSType,
  declaredTypes: Record<string, string[]>
): string[] {
  switch (node.type) {
    case 'TSStringKeyword':
      return ['String']
    case 'TSNumberKeyword':
      return ['Number']
    case 'TSBooleanKeyword':
      return ['Boolean']
    case 'TSObjectKeyword':
      return ['Object']
    case 'TSTypeLiteral':
      // TODO (nice to have) generate runtime property validation
      return ['Object']
    case 'TSFunctionType':
      return ['Function']
    case 'TSArrayType':
    case 'TSTupleType':
      // TODO (nice to have) generate runtime element type/length checks
      return ['Array']

    case 'TSLiteralType':
      switch (node.literal.type) {
        case 'StringLiteral':
          return ['String']
        case 'BooleanLiteral':
          return ['Boolean']
        case 'NumericLiteral':
        case 'BigIntLiteral':
          return ['Number']
        default:
          return [`null`]
      }

    case 'TSTypeReference':
      if (node.typeName.type === 'Identifier') {
        if (declaredTypes[node.typeName.name]) {
          return declaredTypes[node.typeName.name]
        }
        switch (node.typeName.name) {
          case 'Array':
          case 'Function':
          case 'Object':
          case 'Set':
          case 'Map':
          case 'WeakSet':
          case 'WeakMap':
          case 'Date':
          case 'Promise':
            return [node.typeName.name]
          case 'Record':
          case 'Partial':
          case 'Readonly':
          case 'Pick':
          case 'Omit':
          case 'Exclude':
          case 'Extract':
          case 'Required':
          case 'InstanceType':
            return ['Object']
        }
      }
      return [`null`]

    case 'TSParenthesizedType':
      return inferRuntimeType(node.typeAnnotation, declaredTypes)
    case 'TSUnionType':
      return [
        ...new Set(
          [].concat(
            ...(node.types.map(t => inferRuntimeType(t, declaredTypes)) as any)
          )
        )
      ]
    case 'TSIntersectionType':
      return ['Object']

    case 'TSSymbolKeyword':
      return ['Symbol']

    default:
      return [`null`] // no runtime check
  }
}

Domain

Subdomains

Frequently Asked Questions

What does inferRuntimeType() do?
inferRuntimeType() is a function in the vue codebase.
What calls inferRuntimeType()?
inferRuntimeType() is called by 2 function(s): extractRuntimeProps, recordType.

Analyze Your Own Codebase

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

Try Supermodel Free