Angular 如何在Ionic中正确设置AlertInput类型值?
我正在为我的最新项目使用Ionic,但我正在与Alert进行斗争 我以这种方式创建了一个:Angular 如何在Ionic中正确设置AlertInput类型值?,angular,typescript,ionic-framework,Angular,Typescript,Ionic Framework,我正在为我的最新项目使用Ionic,但我正在与Alert进行斗争 我以这种方式创建了一个: const alert = await this.alertController.create({ header: 'Ordering options', inputs: this.order.options.map(option => ({ name: option.name, type: "radio", label: option.readable, v
const alert = await this.alertController.create({
header: 'Ordering options',
inputs: this.order.options.map(option => ({
name: option.name,
type: "radio",
label: option.readable,
value: option.name,
checked: (option.name === this.order.selected),
handler: () => {
this.order.selected = option.name;
this.order.apply();
alert.dismiss();
},
}))
尽管代码可以工作,但爱奥尼亚实验室
编译输出的部分是以下警报:
[ng] ERROR in src/app/overview/order/order-mobile.component.ts(24,7): error TS2322: Type '{ name: any; type: string; label: any; value: any; checked: boolean; handler: () => void; }[]' is not assignable to type 'AlertInput[]'.
[ng] Type '{ name: any; type: string; label: any; value: any; checked: boolean; handler: () => void; }' is not assignable to type 'AlertInput'.
[ng] Types of property 'type' are incompatible.
[ng] Type 'string' is not assignable to type '"number" | "password" | "time" | "text" | "date" | "email" | "search" | "tel" | "url" | "checkbox" | "radio"'.
怎么了
谢谢您的帮助。如果您使用的是typescript 3.5.1,您可以将
作为常量“radio”
使用,否则将“radio”作为“radio”
使用
或者你也可以这样做
inputs: this.order.options.map((option): AlertInput => ({
这里的问题是,除非提供更多信息,否则typescript始终假定其为字符串而不是字符串文字。如果您使用的是typescript 3.5.1,您可以将
“radio”作为常量
,否则“radio”作为“radio”
将起作用
或者你也可以这样做
inputs: this.order.options.map((option): AlertInput => ({
这里的问题是,除非提供更多信息,否则typescript总是假定它是字符串而不是字符串文字