Package com.google.javascript.jscomp

# Class TypeCheck

java.lang.Object
com.google.javascript.jscomp.TypeCheck

All Implemented Interfaces:
  `CompilerPass`, `NodeTraversal.Callback`

public class TypeCheck extends Object implements NodeTraversal.Callback, CompilerPass

Checks the types of JS expressions against any declared type information.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected static final DiagnosticType`
`NOT_A_CONSTRUCTOR`
`protected static final String`
`OVERRIDING_PROTOTYPE_WITH_NON_OBJECT`

## Constructor Summary

Constructors
Constructor
Description
`TypeCheck(AbstractCompiler compiler, ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry, CheckLevel reportMissingOverride, CheckLevel reportUnknownTypes)`
`TypeCheck(AbstractCompiler compiler, ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry, Scope topScope, com.google.javascript.jscomp.MemoizedScopeCreator scopeCreator, CheckLevel reportMissingOverride, CheckLevel reportUnknownTypes)`

## Method Summary

Modifier and Type
Method
Description
`void`
`check(Node node, boolean externs)`
`void`
`process(Node externsRoot, Node jsRoot)`
Main entry point for this phase of processing.
`Scope`
`processForTesting(Node externsRoot, Node jsRoot)`
Main entry point of this phase for testing code.
`boolean`
`shouldTraverse(NodeTraversal t, Node n, Node parent)`
Visits a node in pre order (before visiting its children) and decides whether this node's children should be traversed.
`void`
`visit(NodeTraversal t, Node n, Node parent)`
This is the meat of the type checking.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### OVERRIDING_PROTOTYPE_WITH_NON_OBJECT

protected static final String OVERRIDING_PROTOTYPE_WITH_NON_OBJECT

See Also:
  - Constant Field Values

### NOT_A_CONSTRUCTOR

protected static final DiagnosticType NOT_A_CONSTRUCTOR

## Constructor Details

### TypeCheck

public TypeCheck(AbstractCompiler compiler, ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry, Scope topScope, com.google.javascript.jscomp.MemoizedScopeCreator scopeCreator, CheckLevel reportMissingOverride, CheckLevel reportUnknownTypes)

### TypeCheck

public TypeCheck(AbstractCompiler compiler, ReverseAbstractInterpreter reverseInterpreter, JSTypeRegistry typeRegistry, CheckLevel reportMissingOverride, CheckLevel reportUnknownTypes)

## Method Details

### process

public void process(Node externsRoot, Node jsRoot)
Main entry point for this phase of processing. This follows the pattern for JSCompiler phases.

Specified by:
  `process` in interface `CompilerPass`
Parameters:
  `externsRoot` - The root of the externs parse tree.
  `jsRoot` - The root of the input parse tree to be checked.

### processForTesting

public Scope processForTesting(Node externsRoot, Node jsRoot)
Main entry point of this phase for testing code.

### check

public void check(Node node, boolean externs)

### shouldTraverse

public boolean shouldTraverse(NodeTraversal t, Node n, Node parent)
Description copied from interface: `NodeTraversal.Callback`

Visits a node in pre order (before visiting its children) and decides whether this node's children should be traversed. If children are traversed, they will be visited by `NodeTraversal.Callback.visit(NodeTraversal, Node, Node)` in post order.

Implementations can have side effects (e.g. modifying the parse tree).

Specified by:
  `shouldTraverse` in interface `NodeTraversal.Callback`
Returns:
  whether the children of this node should be visited

### visit

public void visit(NodeTraversal t, Node n, Node parent)
This is the meat of the type checking. It is basically one big switch, with each case representing one type of parse tree node. The individual cases are usually pretty straightforward.

Specified by:
  `visit` in interface `NodeTraversal.Callback`
Parameters:
  `t` - The node traversal object that supplies context, such as the scope chain to use in name lookups as well as error reporting.
  `n` - The node being visited.
  `parent` - The parent of the node n.