Nativebase: defaultProps does not exist on Text

Created on 16 Jun 2018  路  3Comments  路  Source: GeekyAnts/NativeBase

I've upgraded to the latest version of NativeBase. I was using Text.defaultProps.allowFontScaling = false to prevent font scaling. I now get a compilation error: Property 'defaultProps' does not exist on type 'typeof Text'.

react-native, react and native-base version

react-native: 0.55
react: 16.3.1
native-base: 2.5.2

Expected behaviour

Should be able to set the defaultProps.allowFontScaling property.

Actual behaviour

'defaultProps' cannot be accessed on Text class.

Steps to reproduce (code snippet or screenshot)

constructor(props: any) { super(props); Text.defaultProps.allowFontScaling = false; }

All 3 comments

image

text

For those who need to get compilation working while globally setting Text.defaultProps, you can do something ugly like this:

interface TextWithDefaultProps extends Text {
  defaultProps?: { allowFontScaling?: boolean };
}

((Text as unknown) as TextWithDefaultProps).defaultProps =
  ((Text as unknown) as TextWithDefaultProps).defaultProps || {};
((Text as unknown) as TextWithDefaultProps).defaultProps!.allowFontScaling = false; 
// etc.

Alternatively, could just throw a // @ts-ignore above it, and can do a one-liner like Text.defaultProps = { ...(Text.defaultProps || {}), allowFontScaling: false }

Was this page helpful?
0 / 5 - 0 ratings