Unable to add 'title' to AlertController in Ionic 6 app

I am trying to add an AlertController to my Ionic 6 app with the below code:

presentAlert() {
  let alert = this.alertCtrl.create({
    title: 'Low battery',
    subTitle: '10% of battery remaining',
    buttons: ['Dismiss']
  });
  alert.present();
}

However, my IDE is throwing this error message under title: 'Low battery':

Argument of type ‘{ title: string; subTitle: string; buttons: {}; }’ is not assignable to parameter of type ‘AlertOptions’.
Object literal may only specify known properties, and ‘title’ does not exist in type ‘AlertOptions’.

I am copying this code from the ionic documentation, so I don’t know why it’s throwing an error. Can someone please tell me why this is, & how it can be resolved?

title was something that existed in older version of Ionic. As of Ionic 5, all the overlays have a consistent set of options. What you’re looking for is header. Please see our API docs which have the correct information.

2 Likes