Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6208

How to extend React Component prop typing without changing all usages of React.Component

$
0
0

I want to make testID a prop available for all React.Component instances for native testing. Currently, I am adding it to prop type of all the components that are using it. Is there any way where, for example I can define react/index.d.ts and override the Component prop type to include {testID?: string}?

EDIT:

// types/react/index.d.ts

import 'react'
import { Attributes, ClassAttributes } from 'react'

declare namespace react {
  interface IntrinsicAttributes extends Attributes {
    testID?: string
  }
  interface IntrinsicClassAttributes<T> extends ClassAttributes<T> {
    testID?: string
  }
}

I tried the above override, but it's not working, but if I copy the whole react typing file in and then make above changes, it works fine. So I just need proper overriding technique. Can someone please help me in that?


Viewing all articles
Browse latest Browse all 6208

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>