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

How to get the node_modules package types in Typescript

$
0
0

I'm working with NativeBase (the package name doesn't matter) with Typescript.

I'm creating a simple Input component that wraps the NativeBase TextInput. I added a few own properties and spread all other properties to the NativeBase TextInput.It means that the props object should contain my custom properties and the NativeBase TextInput.

My question is: How to describe it properly via typescript without copying the NativePase properties?

import { Input } from 'native-base';type Props = {  // my custom prop  style: object;  // props from NativeBase  onFocus?: () => void;  onBlur?: () => void;}export class TextInput extends Component<Props, State> {  render() {    // without these callbacks in Props typescript will complain    const { style, onFocus, onBlur, ...otherProps } = this.props;    return (<Input style={this.getStyle()} {...otherProps}/>    );  }}

I tried to use type intersection but it doesn't work because the Input isn't a 'type' in general;

type Props = Input & {  // my custom prop  style: object;}

also, I tried to extract Input types via typeof. Didn't help.

type Props = typeof Input & {  // my custom prop  style: object;}

So is there exists a way to avoid copy-pasting the package possible props that I want to use?

Thanks for any help!


Viewing all articles
Browse latest Browse all 6211

Trending Articles



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