'Property 'width' does not exist on type 'false | ImageStyle | RegisteredStyle<ImageStyle> |

I'm trying to put things in order with typing in the project and I can't figure out how to fix the error Property 'width' does not exist on type 'false | ImageStyle | RegisteredStyle<ImageStyle> | RecursiveArray<ImageStyle | Falsy | RegisteredStyle<ImageStyle>>'.   Property 'width' does not exist on type 'false'.

I have property style and in this property I have property width which I get from parent component by props:

style={{
  width: style?.width ? style?.width : width * 0.8,
}}

I have tried to create additional interface with this property:

interface AdditionalImageStyle {
  width: number,
}

and add it to existing interface:

interface ImageProps {
  style?: StyleProp<ImageStyle> | AdditionalImageStyle;
}

but it doesn't work. Also I have tried to resolve it like this:

style?.width as AdditionalImageStyle

How I can tell typescript that property width in style must be of type number?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source