简体   繁体   English

Object 文字只能指定已知属性 Angular/TypeScript

[英]Object literal may only specify known properties Angular/TypeScript

I have an error message:我有一条错误消息:

Type '{ quantity: number; }' is not assignable to type 
'Partial<EditOrderConfirmModalComponent>'.
Object literal may only specify known properties, and 
'quantity' does not exist in type 'Partial<EditOrderConfirmModalComponent>'.

Error message - VSCode错误消息 - VSCode

I don't understand where is the problem?我不明白问题出在哪里?

The method is like this:方法是这样的:

open(): void {
    const modalRef = this.modalService.show(EditOrderConfirmModalComponent, {
        ...NOT_CLOSABLE_MODAL_OPTIONS,
        initialState: {
            quantity: this.order!.quantity
        }
    });
    modalRef.content!.closeModal.pipe(
        takeUntil(this.unsubscribe$)
    ).subscribe(() => {
        modalRef?.hide();
    });
}

In the EditOrderConfirmModalComponent在 EditOrderConfirmModalComponent 中

I have this:我有这个:

export class EditOrderConfirmModalComponent implements OnInit {

    modalService: any;
    private unsubscribe$ = new Subject < void > ();
    @Output() closeModal = new EventEmitter < void > ();
    @Input() orderToEdit ? : Order;

    constructor(
        public modal: BsModalRef,
        private router: Router,
        private location: Location,
        private service: EditOrderService
    ) {}  

For HTML对于 HTML

<td style="min-width: 100%"> {{ orderToEdit.quantity }}</td>

Thank you for your time.感谢您的时间。

your initial state doesn't match the interface of the component.您的初始 state 与组件的接口不匹配。 you probably mean to do:你可能打算这样做:

const modalRef = this.modalService.show(EditOrderConfirmModalComponent, {
    ...NOT_CLOSABLE_MODAL_OPTIONS,
    initialState: {
        orderToEdit: { quantity: this.order!.quantity }
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 angular 4 typescript 验证错误对象文字可能只指定已知属性 - angular 4 typescript validation error Object literal may only specify known properties 错误:对象字面量只能以角度指定已知属性 - error: Object literal may only specify known properties in angular 对象文字只能指定已知属性 - Object Literal May Only Specify Known Properties 对象文字可能只指定已知属性错误 - Object literal may only specify known properties error 对象字面量只能指定已知的属性,并且类型“设置”中不存在“选择” - Object literal may only specify known properties, and 'select' does not exist in type 'Settings' 错误TS2322:对象文字可能仅指定已知属性,并且类型中不存在“标签” - error TS2322: Object literal may only specify known properties, and 'labels' does not exist in type Object 文字可能只指定已知属性,并且“设置”类型中不存在“按钮” - Object literal may only specify known properties, and 'buttons' does not exist in type 'Settings 对象文字只能指定已知的属性,并且&#39;ChatMessage []&#39;类型中不存在&#39;message&#39; - Object literal may only specify known properties and 'message' does not exist in type 'ChatMessage[]' 类型的参数不能分配给类型的参数。对象文字只能指定已知的属性 - Argument of type is not assignable to parameter of type .Object literal may only specify known properties Angular Object文字只能指定知道属性,而...在类型中不存在 - Angular Object literal may only specify know properties and … does not exist in type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM