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.

Type Checking on Typescript project finds errors with an unchanged project

See original GitHub issue

Expected Behavior

Type checking on a unchanged fresh typescript project to return 0 errors

Current Behavior

Type checking on an unchanged fresh typescript project returns

(node:19764) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
  ✔ Generating the Prisma client...
  ✔ Generating types
src/App.tsx:10:4 - error TS2786: 'FatalErrorBoundary' cannot be used as a JSX component.
  Its instance type 'FatalErrorBoundary' is not a valid JSX element.
    The types returned by 'render()' are incompatible between these types.
      Type 'import("/Users/katrinaknight/Projects/redwood/test-app/node_modules/@types/react/index").ReactNode' is not assignable to type 'import("/Users/katrinaknight/Projects/redwood/test-app/node_modules/@types/react-dom/node_modules/@types/react/index").ReactNode'.
        Type '{}' is not assignable to type 'ReactNode'.

10   <FatalErrorBoundary page={FatalErrorPage}>
      ~~~~~~~~~~~~~~~~~~


Found 1 error in src/App.tsx:10

Steps to Reproduce

  1. yarn create redwood-app --ts test-app
  2. cd test-app
  3. yarn rw type-check

Why this effects things

This doesn’t effect me too much right now, as long as it can be ignored and will show other errors in addition to this one, but it is a minor issue if I try to later do CI based on the type-checking.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:6
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

23reactions
Tobbecommented, Apr 10, 2022

Maybe relevant: https://github.com/facebook/react/issues/24304

So I don’t know why we have react-18 types. But the issue here is that in the react 17 types ReactNode includes {}. It was removed in the react 18 types. So assigning from react 17 ReactNode to react 18 ReactNode is not possible (but the other way around would be fine)

React 17:

type ReactFragment = {} | Iterable<ReactNode>;
type ReactNode = ReactChild | ReactFragment | ReactPortal | boolean | null | undefined;

React 18:

type ReactFragment = Iterable<ReactNode>;
type ReactNode = ReactChild | ReactFragment | ReactPortal | boolean | null | undefined;

This is only a problem in RW Apps, not the framework itself. For the framework we still get react 17 typings for both react and react-dom

image

Is it react-syntax-highlighter that’s the problem?

A few other things worth looking into, from a project’s yarn.lock

"@testing-library/react@npm:12.1.4":
  version: 12.1.4
  resolution: "@testing-library/react@npm:12.1.4"
  dependencies:
    "@babel/runtime": ^7.12.5
    "@testing-library/dom": ^8.0.0
    "@types/react-dom": "*"
"@types/react-dom@npm:*":
  version: 18.0.0
  resolution: "@types/react-dom@npm:18.0.0"
  dependencies:
    "@types/react": "*"
"@types/react-syntax-highlighter@npm:11.0.5":
  version: 11.0.5
  resolution: "@types/react-syntax-highlighter@npm:11.0.5"
  dependencies:
    "@types/react": "*"

I found out about the -R flag for yarn why

image


So. Workaround for now:

Add this to your project’s root package.json:

  "resolutions": {
    "@types/react": "17.0.40"
  }
2reactions
thedavidpricecommented, Apr 13, 2022

Related Issue now open on DefinitelyTyped repo: https://github.com/microsoft/DefinitelyTyped-tools/issues/433

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript Errors in a Javascript Project that has no ...
js project (type: javascript) with no ts files in it (go figure) that is throwing 3 typescript errors: Error TS2304 Cannot find name...
Read more >
Achieve Project-Wide Type Checking with TypeScript and ...
Type errors only show up in open files, which only become apparent after a build fails. As it turns out, VS Code does...
Read more >
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
Read more >
Upgrading to 15.5.x causes TS2559 errors to appear in ...
After upgrading from 15.4.x to 15.5.x, a large number of TS2559 errors appear in the Error List window and offending types are underlined...
Read more >
Understanding TypeScript Configuration Options
Normally it will be used as type checking in JavaScript project. ... When checkJs is enabled, TypeScript will raise errors for JavaScript files....
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