demo/typescript.js
function checkFunctionAndClassExpressionBodies(node) {
            switch (node.kind) {
                case 173 /* FunctionExpression */:
                case 174 /* ArrowFunction */:
                    ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
                    checkFunctionExpressionOrObjectLiteralMethodBody(node);
                    break;
                case 186 /* ClassExpression */:
                    ts.forEach(node.members, checkSourceElement);
                    ts.forEachChild(node, checkFunctionAndClassExpressionBodies);
                    break;
                case 143 /* MethodDeclaration */:
                case 142 /* MethodSignature */:
                    ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies);
                    ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
                    if (ts.isObjectLiteralMethod(node)) {
                        checkFunctionExpressionOrObjectLiteralMethodBody(node);
                    }
                    break;
                case 144 /* Constructor */:
                case 145 /* GetAccessor */:
                case 146 /* SetAccessor */:
                case 213 /* FunctionDeclaration */:
                    ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
                    break;
                case 205 /* WithStatement */:
                    checkFunctionAndClassExpressionBodies(node.expression);
                    break;
                case 139 /* Decorator */:
                case 138 /* Parameter */:
                case 141 /* PropertyDeclaration */:
                case 140 /* PropertySignature */:
                case 161 /* ObjectBindingPattern */:
                case 162 /* ArrayBindingPattern */:
                case 163 /* BindingElement */:
                case 164 /* ArrayLiteralExpression */:
                case 165 /* ObjectLiteralExpression */:
                case 245 /* PropertyAssignment */:
                case 166 /* PropertyAccessExpression */:
                case 167 /* ElementAccessExpression */:
                case 168 /* CallExpression */:
                case 169 /* NewExpression */:
                case 170 /* TaggedTemplateExpression */:
                case 183 /* TemplateExpression */:
                case 190 /* TemplateSpan */:
                case 171 /* TypeAssertionExpression */:
                case 189 /* AsExpression */:
                case 172 /* ParenthesizedExpression */:
                case 176 /* TypeOfExpression */:
                case 177 /* VoidExpression */:
                case 178 /* AwaitExpression */:
                case 175 /* DeleteExpression */:
                case 179 /* PrefixUnaryExpression */:
                case 180 /* PostfixUnaryExpression */:
                case 181 /* BinaryExpression */:
                case 182 /* ConditionalExpression */:
                case 185 /* SpreadElementExpression */:
                case 184 /* YieldExpression */:
                case 192 /* Block */:
                case 219 /* ModuleBlock */:
                case 193 /* VariableStatement */:
                case 195 /* ExpressionStatement */:
                case 196 /* IfStatement */:
                case 197 /* DoStatement */:
                case 198 /* WhileStatement */:
                case 199 /* ForStatement */:
                case 200 /* ForInStatement */:
                case 201 /* ForOfStatement */:
                case 202 /* ContinueStatement */:
                case 203 /* BreakStatement */:
                case 204 /* ReturnStatement */:
                case 206 /* SwitchStatement */:
                case 220 /* CaseBlock */:
                case 241 /* CaseClause */:
                case 242 /* DefaultClause */:
                case 207 /* LabeledStatement */:
                case 208 /* ThrowStatement */:
                case 209 /* TryStatement */:
                case 244 /* CatchClause */:
                case 211 /* VariableDeclaration */:
                case 212 /* VariableDeclarationList */:
                case 214 /* ClassDeclaration */:
                case 243 /* HeritageClause */:
                case 188 /* ExpressionWithTypeArguments */:
                case 217 /* EnumDeclaration */:
                case 247 /* EnumMember */:
                case 227 /* ExportAssignment */:
                case 248 /* SourceFile */:
                case 240 /* JsxExpression */:
                case 233 /* JsxElement */:
                case 234 /* JsxSelfClosingElement */:
                case 238 /* JsxAttribute */:
                case 239 /* JsxSpreadAttribute */:
                case 235 /* JsxOpeningElement */:
                    ts.forEachChild(node, checkFunctionAndClassExpressionBodies);
                    break;
            }
        }
function checkFunctionAndClassExpressionBodies(node) {
            switch (node.kind) {
                case 173 /* FunctionExpression */:
                case 174 /* ArrowFunction */:
                    ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
                    checkFunctionExpressionOrObjectLiteralMethodBody(node);
                    break;
                case 186 /* ClassExpression */:
                    ts.forEach(node.members, checkSourceElement);
                    ts.forEachChild(node, checkFunctionAndClassExpressionBodies);
                    break;
                case 143 /* MethodDeclaration */:
                case 142 /* MethodSignature */:
                    ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies);
                    ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
                    if (ts.isObjectLiteralMethod(node)) {
                        checkFunctionExpressionOrObjectLiteralMethodBody(node);
                    }
                    break;
                case 144 /* Constructor */:
                case 145 /* GetAccessor */:
                case 146 /* SetAccessor */:
                case 213 /* FunctionDeclaration */:
                    ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies);
                    break;
                case 205 /* WithStatement */:
                    checkFunctionAndClassExpressionBodies(node.expression);
                    break;
                case 139 /* Decorator */:
                case 138 /* Parameter */:
                case 141 /* PropertyDeclaration */:
                case 140 /* PropertySignature */:
                case 161 /* ObjectBindingPattern */:
                case 162 /* ArrayBindingPattern */:
                case 163 /* BindingElement */:
                case 164 /* ArrayLiteralExpression */:
                case 165 /* ObjectLiteralExpression */:
                case 245 /* PropertyAssignment */:
                case 166 /* PropertyAccessExpression */:
                case 167 /* ElementAccessExpression */:
                case 168 /* CallExpression */:
                case 169 /* NewExpression */:
                case 170 /* TaggedTemplateExpression */:
                case 183 /* TemplateExpression */:
                case 190 /* TemplateSpan */:
                case 171 /* TypeAssertionExpression */:
                case 189 /* AsExpression */:
                case 172 /* ParenthesizedExpression */:
                case 176 /* TypeOfExpression */:
                case 177 /* VoidExpression */:
                case 178 /* AwaitExpression */:
                case 175 /* DeleteExpression */:
                case 179 /* PrefixUnaryExpression */:
                case 180 /* PostfixUnaryExpression */:
                case 181 /* BinaryExpression */:
                case 182 /* ConditionalExpression */:
                case 185 /* SpreadElementExpression */:
                case 184 /* YieldExpression */:
                case 192 /* Block */:
                case 219 /* ModuleBlock */:
                case 193 /* VariableStatement */:
                case 195 /* ExpressionStatement */:
                case 196 /* IfStatement */:
                case 197 /* DoStatement */:
                case 198 /* WhileStatement */:
                case 199 /* ForStatement */:
                case 200 /* ForInStatement */:
                case 201 /* ForOfStatement */:
                case 202 /* ContinueStatement */:
                case 203 /* BreakStatement */:
                case 204 /* ReturnStatement */:
                case 206 /* SwitchStatement */:
                case 220 /* CaseBlock */:
                case 241 /* CaseClause */:
                case 242 /* DefaultClause */:
                case 207 /* LabeledStatement */:
                case 208 /* ThrowStatement */:
                case 209 /* TryStatement */:
                case 244 /* CatchClause */:
                case 211 /* VariableDeclaration */:
                case 212 /* VariableDeclarationList */:
                case 214 /* ClassDeclaration */:
                case 243 /* HeritageClause */:
                case 188 /* ExpressionWithTypeArguments */:
                case 217 /* EnumDeclaration */:
                case 247 /* EnumMember */:
                case 227 /* ExportAssignment */:
                case 248 /* SourceFile */:
                case 240 /* JsxExpression */:
                case 233 /* JsxElement */:
                case 234 /* JsxSelfClosingElement */:
                case 238 /* JsxAttribute */:
                case 239 /* JsxSpreadAttribute */:
                case 235 /* JsxOpeningElement */:
                    ts.forEachChild(node, checkFunctionAndClassExpressionBodies);
                    break;
            }
        }
Function and class expression bodies are checked after all statements in the enclosing body. This is to ensure constructs like the following are permitted: let foo = function () { let s = foo(); return "hello"; } Here, performing a full type check of the body of the function expression whilst in the process of determining the type of foo would cause foo to be given type any because of the recursive reference. Delaying the type check of the body ensures foo has been assigned a type.