Skip to content

Commit f549667

Browse files
authored
fix(core): improve strong type src of Image (NativeScript#10265)
1 parent 2b64e17 commit f549667

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

packages/core/ui/image/image-common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Trace } from '../../trace';
1414
@CSSType('Image')
1515
export abstract class ImageBase extends View implements ImageDefinition {
1616
public imageSource: ImageSource;
17-
public src: string | ImageSource;
17+
public src: string | ImageSource | ImageAsset;
1818
public isLoading: boolean;
1919
public stretch: CoreTypes.ImageStretchType;
2020
public loadMode: 'sync' | 'async';
@@ -134,7 +134,7 @@ export const imageSourceProperty = new Property<ImageBase, ImageSource>({
134134
});
135135
imageSourceProperty.register(ImageBase);
136136

137-
export const srcProperty = new Property<ImageBase, any>({ name: 'src' });
137+
export const srcProperty = new Property<ImageBase, string | ImageSource | ImageAsset>({ name: 'src' });
138138
srcProperty.register(ImageBase);
139139

140140
export const loadModeProperty = new Property<ImageBase, 'sync' | 'async'>({

packages/core/ui/image/index.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class Image extends ImageBase {
186186
[srcProperty.getDefault](): any {
187187
return undefined;
188188
}
189-
[srcProperty.setNative](value: any) {
189+
[srcProperty.setNative](value: string | ImageSource | ImageAsset) {
190190
this._createImageSourceFromSrc(value);
191191
}
192192
}

packages/core/ui/image/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { View } from '../core/view';
22
import { Style } from '../styling/style';
33
import { ImageSource } from '../../image-source';
4+
import { ImageAsset } from '../../image-asset';
45
import { Color } from '../../color';
56
import { Property, InheritedCssProperty } from '../core/properties';
67
import { CoreTypes } from '../../core-types';
@@ -27,7 +28,7 @@ export class Image extends View {
2728
/**
2829
* Gets or sets the source of the Image. This can be either an URL string or a native image instance.
2930
*/
30-
src: any;
31+
src: string | ImageSource | ImageAsset;
3132

3233
/**
3334
* Gets a value indicating if the image is currently loading.
@@ -66,7 +67,7 @@ export class Image extends View {
6667
}
6768

6869
export const imageSourceProperty: Property<Image, ImageSource>;
69-
export const srcProperty: Property<Image, any>;
70+
export const srcProperty: Property<Image, string | ImageSource | ImageAsset>;
7071
export const isLoadingProperty: Property<Image, string>;
7172
export const loadMode: Property<Image, 'sync' | 'async'>;
7273
export const stretchProperty: Property<Image, CoreTypes.ImageStretchType>;

packages/core/ui/image/index.ios.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ImageBase, stretchProperty, imageSourceProperty, tintColorProperty, srcProperty } from './image-common';
22
import { ImageSource } from '../../image-source';
3+
import { ImageAsset } from '../../image-asset';
34
import { Color } from '../../color';
45
import { Trace } from '../../trace';
56
import { layout, queueGC } from '../../utils';
@@ -190,7 +191,7 @@ export class Image extends ImageBase {
190191
this._setNativeImage(value ? value.ios : null);
191192
}
192193

193-
[srcProperty.setNative](value: any) {
194+
[srcProperty.setNative](value: string | ImageSource | ImageAsset) {
194195
this._createImageSourceFromSrc(value);
195196
}
196197
}

0 commit comments

Comments
 (0)