【问题标题】:Nativescript Typescript error property does not existNativescript Typescript 错误属性不存在
【发布时间】:2016-10-17 20:25:08
【问题描述】:

您好,我正在尝试在 typescript xml 页面中获取 Image 元素并以编程方式设置它的 imageSource 属性。

在我发现的示例中是这样完成的:

image = page.getViewById("id");
image.imageSource = newImageSource;

我在使用 typescript 时遇到的问题是

error 'imageSource' does not exist on type 'View'

我不知道如何解决这个问题。有什么想法吗?

【问题讨论】:

标签: typescript nativescript imagesource


【解决方案1】:

image = <Image> page.getViewById('whatever'); 应该解决类型问题。确保导入图像模块,以便您拥有正确的类。

【讨论】:

  • 谢谢。这正是我一直在寻找的。另一个问题中有人提议使用var image: any = page.getViewById("whatever"),但这似乎更像是解决问题而不是实际解决方案。
  • 是的,强制转换为 any 是一种解决方法,但是您会失去类型的好处 :) 很高兴它有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-02-21
  • 2019-04-12
  • 2020-07-09
  • 2019-10-20
  • 2021-09-26
  • 1970-01-01
  • 2021-09-06
相关资源
最近更新 更多