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

Component fails to auto import types from index.d.ts file in React Native

$
0
0

I have a component called ColorBox, and inside of its folder I have the component itself, style of it and an index file and the index.d.ts file for my types:

  ColorBox   |- Colorbox.tsx   |- index.ts   |- styles.ts   |- index.d.ts

Here is my index.d.ts file:

export interface IProps {  colorName: string;  colorHex: string;}export interface IBGColor {  backgroundColor: string;}

and this is my ColorBox.tsx component:

import React from 'react';import { View, Text, StyleSheet } from 'react-native';import styles from './styles';const ColorBox: React.FC<IProps> = ({ colorName, colorHex }) => {  const boxColor: IBGColor = {    backgroundColor: colorHex,  };  return (<View style={[styles.box, boxColor]}><Text style={styles.boxText}>{colorName}</Text></View>  );};export default ColorBox;

The problem is that the IProps and IBGColor types does not auto imported from index.d.ts file, how does it works, I've been reading articles about TypeScript and it was mentioned that if you put an index.d.ts file inside of of the module, TypeScript will rely on that and try to find types from that file, but why it does not work in my component?

Should I explicitly import used types inside of my module? If so, then what is the benefit that index.d.ts file provides to us?

Also I use regular react-native init project, not any other fancy boilerplates!


Viewing all articles
Browse latest Browse all 6287

Trending Articles