Nativescript Typescript错误属性不存在

xer*_*ant 1 imagesource typescript nativescript

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

在示例中,我发现它是通过以下方式完成的:

image = page.getViewById("id");
image.imageSource = newImageSource;
Run Code Online (Sandbox Code Playgroud)

我在使用打字稿时遇到的问题是

error 'imageSource' does not exist on type 'View'
Run Code Online (Sandbox Code Playgroud)

我不知道如何解决该问题。有任何想法吗?

Bra*_*tin 5

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