Skip to content

ionic4/angular: overlay getTop can return undefined #17801

Closed

Description

@Pierrci

Bug Report

Ionic version:

[x] 4.x

Current behavior:
In the angular package, the return type of the getTop method in OverlayBaseController is Promise<Overlay>

Expected behavior:
The return type should be Promise<Overlay | undefined>

Steps to reproduce:
Use any component extending OverlayBaseController and call the getTop method without any alert currently present. With the AlertController for example, returned object will be of type Promise<HTMLIonAlertElement>, while it should be Promise<HTMLIonAlertElement | undefined>.

Related code:

import { Component, OnInit } from '@angular/core';
import { AlertController } from '@ionic/angular';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
  constructor(private alertController: AlertController) {}

  async ngOnInit() {
    const undefinedAlert = await this.alertController.getTop(); // typed as HTMLIonAlertElement
    alert(`type of alert is ${typeof undefinedAlert}`); // typeof undefinedAlert === 'undefined'
	undefinedAlert.dismiss(); // still possible because of the typing, will throw an error
  }
}

Other information:

Ionic info:

Ionic:

   ionic (Ionic CLI)             : 4.10.3 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.1.1
   @angular-devkit/build-angular : 0.13.6
   @angular-devkit/schematics    : 7.2.4
   @angular/cli                  : 7.3.6
   @ionic/angular-toolkit        : 1.4.0

System:

   NodeJS : v11.6.0 (/usr/local/bin/node)
   npm    : 6.5.0
   OS     : macOS Mojave

Activity

  1. Pierrci commented on Mar 15, 2019

    @Pierrci
    ContributorAuthor

    Just submitted the related PR

  2. added
    type: bug
    on Mar 15, 2019
  3. added
    package: angular
    on Jun 5, 2019
  4. brandyscarney commented on Jun 5, 2019

    @brandyscarney
    Member

    It seems the PR was merged so I'm going to close this, thanks for the issue!

  5. ionitron-bot commented on Jul 5, 2019

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  6. locked and limited conversation to collaborators on Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: angulartype: bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions