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

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 been read a lot of articles about typescript and ther were 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? any hint of help will be appreciated.

i mean 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 6214

Trending Articles



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