【问题标题】:Argument of type '"68488"' is not assignable to parameter of type 'Guid'.ts(2345)'"68488"' 类型的参数不可分配给 'Guid'.ts(2345) 类型的参数
【发布时间】:2020-06-07 21:00:47
【问题描述】:

在为数据库主键使用 Guid 类型参数时。这是使用 Guid 类型的 Angular 前端界面:

import { Guid } from 'guid-typescript';

export interface IProduct {
    id: Guid;
    name: string;
    description: string;
    price: number;
    pictureUrl: string;
    productType: string;
    productBrand: string;
  }

尝试在以下函数中发送 Guid 类型参数时,出现语法错误,“xxx68488x”类型的参数不可分配给“Guid”类型的参数。ts(2345)

  loadProduct(){
   this.shopService.getProduct('dba3ac76-1201-4fe1-8460-8d5de684886c').subscribe
   (response => {this.product = response;
  }, error => {
    console.log(error);
  });
  }
}

这个参数下面有一条红色的波浪线。如何传递 Guid 参数?

【问题讨论】:

    标签: angular


    【解决方案1】:

    调用Guid.parse 方法将其从string 转换为Guid 类型:

    this.shopService.getProduct(Guid.parse('dba3ac76-1201-4fe1-8460-8d5de684886c'))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-16
      • 2022-11-30
      • 1970-01-01
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      相关资源
      最近更新 更多