Repository: oppia/oppia
File: core/templates/components/ck-editor-helpers/ck-editor-4-rte.component.ts (TypeScript)

Code before:
  componentsThatRequireInternet: string[] = [];
  subscriptions: Subscription;
  // A RegExp for matching rich text components.
  componentRe = /(<(oppia-noninteractive-(.+?))\b[^>]*>)[\s\S]*?<\/\2>/g;

  configError: string | null = null;
  pasteError: string | null = null;
  pendingPasteData: string | null = null;
  pendingPasteValidContent: string | null = null;
  showPasteConfirmation: boolean = false;

  @ViewChild('oppiaRTE') oppiaRTE: ElementRef;

  constructor(
    private ckEditorCopyContentService: CkEditorCopyContentService,
    private pageContextService: PageContextService,
    private elementRef: ElementRef,
    private internetConnectivityService: InternetConnectivityService,
    private renderer: Renderer2
  ) {
    this.rteHelperService = OppiaAngularRootComponent.rteHelperService;
    this.subscriptions = new Subscription();
  }

  ngOnInit(): void {
    this.validateConfiguration();
    this.subscriptions.add(
      this.internetConnectivityService.onInternetStateChange.subscribe(
        internetAccessible => {
          if (internetAccessible) {
            this.enableRTEicons();
            this.connectedToInternet = internetAccessible;
          } else {
            this.disableRTEicons();
            this.connectedToInternet = internetAccessible;
          }
        }
      )
    );
  }

  private validateConfiguration(): void {
    if (!this.uiConfig || !this.uiConfig.rte_component_config_id) {
      this.configError =
        'No component set specified. Please provide a "rte_component_config_id" config in uiConfig.';
      console.error('Error: ' + this.configError);
      return;
    }

    const rteComponents = this.uiConfig.rte_component_config_id;
    const componentList = AppConstants.RTE_COMPONENT_CONFIGS[rteComponents];

Review comment (refactor):
If you have already defined ``rteHelperService: RteHelperService;`` above, then do we need to typecast here?

Code after:
  currentValue: string = '';
  connectedToInternet = true;
  headersEnabled = false;
  windowIsNarrow = false;
  componentsThatRequireInternet: string[] = [];
  subscriptions: Subscription;
  // A RegExp for matching rich text components.
  componentRe = /(<(oppia-noninteractive-(.+?))\b[^>]*>)[\s\S]*?<\/\2>/g;

  configError: string | null = null;
  pasteError: string | null = null;
  pendingPasteData: string | null = null;
  pendingPasteValidContent: string | null = null;
  showPasteConfirmation: boolean = false;

  @ViewChild('oppiaRTE') oppiaRTE!: ElementRef;

  constructor(
    private ckEditorCopyContentService: CkEditorCopyContentService,
    private pageContextService: PageContextService,
    private elementRef: ElementRef,
    private internetConnectivityService: InternetConnectivityService,
    private renderer: Renderer2
  ) {
    this.rteHelperService =
      OppiaAngularRootComponent.rteHelperService as RteHelperService;
    this.subscriptions = new Subscription();
  }

  ngOnInit(): void {
    this.validateConfiguration();
    this.subscriptions.add(
      this.internetConnectivityService.onInternetStateChange.subscribe(
        internetAccessible => {
          if (internetAccessible) {
            this.enableRTEicons();
            this.connectedToInternet = internetAccessible;
          } else {
            this.disableRTEicons();
            this.connectedToInternet = internetAccessible;
          }
        }
      )
    );
  }

  private validateConfiguration(): void {
    if (!this.uiConfig || !this.uiConfig.rte_component_config_id) {
      this.configError =
        'No component set specified. Please provide a "rte_component_config_id" config in uiConfig.';
      console.error('Error: ' + this.configError);