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
  58009d44_c2df_89c8_226b_0f5828dc8e12["inferRuntimeType()"]
  c9346cac_54e3_f6ca_68a7_03c6e82c9609["compileScript.ts"]
  58009d44_c2df_89c8_226b_0f5828dc8e12 -->|defined in| c9346cac_54e3_f6ca_68a7_03c6e82c9609
  d0f5ebe6_ca7a_17bd_e29b_5326c7ef914b["recordType()"]
  d0f5ebe6_ca7a_17bd_e29b_5326c7ef914b -->|calls| 58009d44_c2df_89c8_226b_0f5828dc8e12
  2c50a6c2_cede_55c3_a14b_5f395f412ebe["extractRuntimeProps()"]
  2c50a6c2_cede_55c3_a14b_5f395f412ebe -->|calls| 58009d44_c2df_89c8_226b_0f5828dc8e12
  style 58009d44_c2df_89c8_226b_0f5828dc8e12 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']

Domain

Subdomains

Frequently Asked Questions

What does inferRuntimeType() do?
inferRuntimeType() is a function in the vue codebase, defined in packages/compiler-sfc/src/compileScript.ts.
Where is inferRuntimeType() defined?
inferRuntimeType() is defined in packages/compiler-sfc/src/compileScript.ts at line 1469.
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