question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typing error with React 18

See original GitHub issue

Describe the bug

NextJS build is failing with React 18 and usage of <Trans> component.

Occurs in next-i18next version

11.0.0

Steps to reproduce

info  - Loaded env from /.env
Failed to compile.

./src/components/Component.tsx:179:56
Type error: Type '{ freeDays: number; }' is not assignable to type 'ReactNode'.
  Object literal may only specify known properties, and 'freeDays' does not exist in type 'ReactElement<any, string | JSXElementConstructor<any>> | ReactFragment | ReactPortal'.

  177 |                     <Trans i18nKey="subscribe.freeDays">
  178 |                       You get
> 179 |                       <span className="family-bold">{{ freeDays }}</span>
      |                                                        ^
  180 |                       &nbsp;starting today
  181 |                     </Trans>
  182 |                   </p>
info  - Checking validity of types .%   

Expected behaviour

No typing errors when using variables in Trans component

OS (please complete the following information)

  • Device: MBP 2019 16
  • Browser: Chrome 100.0.4896.127

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
azukencommented, Jul 19, 2022

@pedrodurek Unfortunately, still not working !

It overrides React own definition types, so I’ve got an error like :

Type error: Module '"react"' has no exported member 'useEffect'.

  3 | import Head from 'next/head';
  4 | import Link from 'next/link';
> 5 | import React, { useEffect } from 'react';
    |                 ^
  6 | import StaticPageManager from 'src/containers/StaticPageManager';
  7 | import { captureError } from 'src/utils/sentry/error-handler';
  8 | import NoHeaderFooterLayout from '../Layout/NoHeaderFooter';

I’ve searched and tried to fix this, changing d.ts file :

import React from 'react';

type ReactI18NextChild = React.ReactNode | Record<string, unknown>;

declare global {
  namespace React {
    interface HTMLAttributes<T> {
      children?: ReactI18NextChild | Iterable<ReactI18NextChild>;
    }
  }
}

Declare file into tsconfig.json (both include and typeRoots properties), changing file name but it continues to override base types.

1reaction
adraicommented, Jul 18, 2022

@pedrodurek can you help…? There is probably a bit of confusion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: React 18 types broken since the type release a ... - GitHub
Can we move this issue discussion to the DefinitelyTyped repository? That's where the React typings are maintained, and you'll probably see more ...
Read more >
React sur Twitter : "The React 18 TypeScript typings are out ...
The previous typings incorrectly included “children” into props by default even though some components don't accept children or accept a different type.
Read more >
React v18 causes error without code changes, JSX no longer ...
It seems to me that with v18 React expects React Nodes everywhere and JSX as such is no longer accepted. These errors disappear...
Read more >
Upgrading to React 18 with TypeScript - LogRocket Blog
The upgrade of the React type definitions to support React 18 involved some significant breaking changes that developers should know about.
Read more >
React 18 - Property 'children' does not exist fix [2022] - YouTube
If you have recently upgraded to React 18 and tried to follow ... run into the error : Property 'children' does not exist...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found