Skip to main content

TS Errors

!add

export const EventComponent: React.FC = () => {
const onChange = (e) => console.log(e);


return (
<div\>
<input onChange={onChange} /\>
</div\>
);
};

!cannot create empty .tsx files

'Parent.tsx' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.ts(1208)

!cannot create JSX w/o explicit children

Type '{ children: never[]; color: string; onClick: () => void; }' is not assignable to type 'IntrinsicAttributes & ChildProps'.
Property 'children' does not exist on type 'IntrinsicAttributes & ChildProps'.ts(2322)

!forgot to add store to Provider

const App = () => {
return (
<Provider\></Provider\>
);
};
Property 'store' is missing in type '{ children: Element; }' but required in type 'Readonly<ProviderProps<AnyAction\>\>'.
Overload 2 of 2, '(props: ProviderProps<AnyAction\>, context: any): Provider<AnyAction\>', gave the following error.

!must TS annotate catch(err) as any or unknown

Catch clause variable type annotation must be 'any' or 'unknown' if specified.ts(1196)

!update lib to fix type definition that accepts children

Type '{ children: Element; store: Store<{ readonly [$CombinedState]?: undefined; } & { repo: never; }, Action\> & { dispatch: unknown; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Provider<Action\>\> & Readonly<ProviderProps<Action\>\>'.

add useState<string[]>([]) if expecting array of strings

automated script to transform outdated types from React 17 to 18 - GitHub - eps1lon/types-react-codemod: Collection of transforms for jscodeshift related to @types/react

Fix the following issue, by adding the correct type to the interface

Property 'children' does not exist on type 'MyProps'.ts(2339)

interface MyProps { color: string; children?: React.ReactNode; }

interface MyProps {
color: string;
children?: React.ReactNode;
}

let timer: NodeJS.Timeout OR ReturnType<typeof setTimeout\>

let timer: any
Variable 'timer' implicitly has an 'any' type.ts(7005)

must ts-annotate try-catch err

(local var) err: unknown
Object is of type 'unknown'.ts(2571)

outdated Type Definitions will throw error about not being allowed to accept children, unless all interfaces are updated!!

Parameter 'e' implicitly has an 'any' type.ts(7006)

React 18 Change requires children prop to be explicitly defined

interface MyProps {
color: string;
children?: React.ReactNode;
}

React 18 Update changes TypeScript children prop

children?: React.ReactNode;

reactjs.org/blog/2022/03/08/react 18 upgrade guide.html#updates to typescript definitions

TS infers type "never" for init {} or [] in useState()

Type 'string' is not assignable to type 'never'.ts(2322)

type inference expects empty array; hence "never"

type inference only apply to in-line

const onChange = (e: React.ChangeEvent<HTMLInputElement\>) => console.log(e);

References