You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: return_type.rs
    path of file: ./repos/stc/crates/stc_ts_file_analyzer/src/analyzer/stmt
    
    the code of the file until where you have to start completion: #![allow(clippy::if_same_then_else)]

use std::{borrow::Cow, mem::take, ops::AddAssign};

use rnode::{Fold, FoldWith, Visit, VisitWith};
use stc_ts_ast_rnode::{RBreakStmt, RIdent, RReturnStmt, RStmt, RStr, RThrowStmt, RTsEntityName, RTsLit, RYieldExpr};
use stc_ts_errors::{DebugExt, ErrorKind};
use stc_ts_simple_ast_validations::yield_check::YieldValueUsageFinder;
use stc_ts_types::{
    CommonTypeMetadata, Index, IndexedAccessType, Instance, Key, KeywordType, KeywordTypeMetadata, LitType
    
    fn validate(&mut self, e: &RYieldExpr) -> VResult<Type> {
        let span = e.span;

        if let Some(res) = e.arg.validate_with_default(self) {
            let ty = res?;

            let item_ty = if e.delegate {
                if self.ctx.in_async {
                    self.get_async_iterator_element_type(e.span, Cow::Owned(ty), false)
                        .context("tried to convert argument as an async iterator for delegating yield")?
                        .into_owned()
                } else {
                    self.get_iterator_element_type(e.span, Cow::Owned(ty), false, GetIteratorOpts { ..Default::default() })
                        .context("tried to convert argument as an iterator for delegating yield")?
                        .into_owned()
                }
            } else {
                ty
            }
            .freezed();

            if let Some(declared) = self.scope.declared_return_type().cloned() {
                match if self.ctx.in_async {
                    self.get_async_iterator_element_type(e.span, Cow::Owned(declared), true)
                        .context("tried to get an element type from an async iterator for normal yield")
                } else {
                    self.get_iterator_element_type(e.span, Cow::Owned(declared), true, GetIteratorOpts { ..Default::default() })
                        .context("tried to get an element type from an iterator for normal yield")
                }
                .map(Cow::into_owned)
                .map(Freeze::freezed)
                {
                    Ok(declared) => {
                        let declared = Type::Instance(Instance {
                            span: declared.span(),
                            ty: Box::new(declared),
                            metadata: Default::default(),
                            tracker: Default::default(),
                        });

                        match self.assign_with_opts(
                            &mut Default::default(),
                            &declared,
                            &item_ty,
                            AssignOpts {
                                span: e.span,
                                allow_unknown_rhs: Some(true),
                                use_missing_fields_for_class: true,
                                may_unwrap_promise: true,
                                ..Default::default()
                            },
                        ) {
                            Ok(()) => {}
                            Err(err) => {
                                self.storage.report(err);
                                return Ok(Type::any(span, Default::default()));
                            }
                        }
                    }
                    Err(err) => {
                        self.storage.report(
                            ErrorKind::SimpleAssignFailed {
                                span,
                                cause: Some(Box::new(err)),
                            }
                            .into(),
                        );
                        return Ok(Type::any(span, Default::default()));
                    }
                }
            }

            self.scope.return_values.yield_types.push(item_ty);
        } else {
            self.scope
                .return_values
                .yield_types
                .push(Type::undefined(e.span, Default::default()));
        }

        Ok(Type::any(e.span, Default::default()))
    }