Como exigir uma função como parâmetro em typescript

Multi tool use

Como exigir uma função como parâmetro em typescript
Quero generalizar em um serviço uma função de criar popups do Ionic 3
aqui está o serviço
`import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AlertController, ToastController } from 'ionic-angular';
export interface button {
text: string,
handler: any // function
}
@Injectable()
export class MessagesProvider {
constructor(
public http: HttpClient,
public alertCtrl: AlertController,
public toastCtrl: ToastController,
) { }
popupCreator(title: string, message: string, buttons: button) {
return this.alertCtrl.create({
title: title,
message: message,
buttons: buttons
}).present()
}
showToast(text:string, position:string , duration?:number) {
return this.toastCtrl.create({
message: text,
duration: duration ? duration : 3000,
position: position
}).present();
}
}`
essa é a função original
`this.alertCtrl.create({
title: 'Texto',
message: 'mensagem',
buttons: [{
text: 'CANCELAR',
handler: () => { }
},
{
text: 'OK',
handler: () => { funcaoParametro(); }
}
]
})present();`
então o que eu estou tentando fazer é obrigar quem usar o serviço a enviar um objeto no formato correto de buttons que executaria a função parâmetro desejada.
Isso é possível?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
This site is in English. Either you want Stack Overflow en español or Stack Overflow em Português.
– Some programmer dude
10 secs ago