src/com/google/javascript/jscomp/TypeCheck.java
/** Visits the loop variable of a FOR_OF and verifies the type being assigned to it */
Visits the loop variable of a FOR_OF and verifies the type being assigned to it
Visits the loop variable of a FOR_OF and verifies the type being assigned to it
private void checkForOfTypes(NodeTraversal t, Node forOf) {
    Node lhs = forOf.getFirstChild();
    Node iterable = forOf.getSecondChild();
    JSType iterableType = getJSType(iterable);
    iterableType = iterableType.autobox();
    JSType actualType =
        iterableType
            .getTemplateTypeMap()
            .getResolvedTemplateType(typeRegistry.getIterableTemplate());
    if (NodeUtil.isNameDeclaration(lhs)) {
      lhs = lhs.getFirstChild();
    }
    if (lhs.isDestructuringLhs()) {
      lhs = lhs.getFirstChild();
    }
    checkCanAssignToWithScope(
        t,
        forOf,
        lhs,
        actualType,
        lhs.getJSDocInfo(),
        "declared type of for-of loop variable does not match inferred type");
  }
private void checkForOfTypes ( NodeTraversal t , Node forOf ) { Node lhs = forOf . getFirstChild ( ) ; Node iterable = forOf . getSecondChild ( ) ; JSType iterableType = getJSType ( iterable ) ; iterableType = iterableType . autobox ( ) ; JSType actualType = iterableType . getTemplateTypeMap ( ) . getResolvedTemplateType ( typeRegistry . getIterableTemplate ( ) ) ; if ( NodeUtil . isNameDeclaration ( lhs ) ) { lhs = lhs . getFirstChild ( ) ; } if ( lhs . isDestructuringLhs ( ) ) { lhs = lhs . getFirstChild ( ) ; } checkCanAssignToWithScope ( t , forOf , lhs , actualType , lhs . getJSDocInfo ( ) , "declared type of for-of loop variable does not match inferred type" ) ; }
Visits the loop variable of a FOR_OF and verifies the type being assigned to it
Visits the loop variable of a FOR_OF and verifies the type being assigned to it
// Convert primitives to their wrapper type and remove null/undefined // If iterable is a union type, autoboxes each member of the union. // e.g. get "x" given the VAR in "for (var x of arr) {" // e.g. get `[x, y]` given the VAR in `for (var [x, y] of arr) {`