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 a reference to 'react-native/node_modules/@types/react'. This is likely not portable. A type annotation is necessary.
I tried several things, but the error remains the same:
- Following this post, I added
import React from "react";
- Tried to disable tslint by adding
/* tslint:disable */
above theBody
declaration - Tried to disable tslint by adding
// tslint:disable-next-line
above theBody
declaration - Played with dependency versions. Currently I have
"@types/react": "^16.9.49"
.
node_modules
directory innode_modules/react-native/
You have conflicting dependencies – Santiago@types
directory insidenode_modules/react-native/
– Paprikanode_modules
andpackage-lock.json
or whatever the lockfile is for your package manger and reinstall all dependencies – Santiago