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

Need help fixing or suppressing this tslint error: TS2742

$
0
0

I have this file in a react native project:

import styled, { withTheme } from 'styled-components';import { BaseText } from '../BaseText';export interface BodyProps {  textAlign?: string;  fontSize?: string;}export const Body = withTheme(styled(BaseText)<BodyProps>`  text-align: ${props => (props.textAlign ? props.textAlign : 'center')};  font-size: ${props => (props.fontSize ? props.fontSize : '16px')};`);

I upgraded react native from 0.61.5 to 0.63.2 and started getting this lint error wherever withTheme is being used:

TS2742: The inferred type of 'Body' cannot be named without areference to 'react-native/node_modules/@types/react'. This is likelynot portable. A type annotation is necessary.

I tried several things, but the error remains the same:

  1. Following this post, I added import React from "react";
  2. Tried to disable tslint by adding /* tslint:disable */ above the Body declaration
  3. Tried to disable tslint by adding // tslint:disable-next-line above the Body declaration
  4. Played with dependency versions. Currently I have "@types/react": "^16.9.49".

Viewing all articles
Browse latest Browse all 6214

Trending Articles



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