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.

Fix `getting-started.tsx` type check

See original GitHub issue

Bug description

The getting-started.tsx file fails the type check ran by the pre-commit hook with the following message:

src/components/pages/home/section/getting-started.tsx:1:26 - error TS2307: Cannot find module '@site/src/components/molecules/animations/fade-into-view' or its corresponding type declarations.

1 import FadeIntoView from '@site/src/components/molecules/animations/fade-into-view';
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/components/pages/home/section/getting-started.tsx:2:18 - error TS2307: Cannot find module '@docusaurus/Link' or its corresponding type declarations.

2 import Link from '@docusaurus/Link';
                   ~~~~~~~~~~~~~~~~~~


Found 2 errors in the same file, starting at: src/components/pages/home/section/getting-started.tsx:1

Steps to reproduce

To reproduce it, run the following command:

npx tsc --skipLibCheck --noEmit --jsx react --esModuleInterop src/components/pages/home/section/getting-started.tsx

Alternatively, modify the file, stage it and run:

npx lefthook run pre-commit

Expected behavior

The type check should not fail.

Additional details

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
timagixecommented, Sep 4, 2022

Hi @webbertakken, @EricRibeiro, I have opened PR that fixes those type errors when running type check on pre-commit step.

It appears that tsc fallbacks to default compiler configuration when running on specific files, i.e. tsc ./src/index.tsx - runs with default configuration, while tsc runs with configuration from tsconfig.json. Docs - tsc CLI Options docs.

# Emit JS for just the index.ts with the compiler defaults
tsc index.ts
# Emit JS for any .ts files in the folder src, with the default settings
tsc src/*.ts

That’s why type check on pre-commit step was failing, since configuration specified in tsconfig.json was ignored and instead the default one was used.

1reaction
webbertakkencommented, Sep 2, 2022

Note that there are 2 different causes.

  • '@docusaurus/Link' should resolve types from the Docusaurus project.
  • '@site/src/components/molecules/animations/fade-into-view'; is a first party component that should either be inferred (after point 1 is fixed) or we’d have to manually add types for it if that is somehow not possible.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started with React and TypeScript - This Dot Labs
By fixing our function and returning JSX, HelloWorld now passes TypeScript's type checks and no error is thrown. As a result, our project...
Read more >
Static Type Checking - React
Flow is a static type checker for your JavaScript code. It is developed at Facebook and is often used with React. It lets...
Read more >
Type check test files · Issue #5626 · facebook/create-react-app
Bug report I created a new project with the --typescript flag, and added a type for my component's props like so: type AppProps...
Read more >
Troubleshooting Handbook: Types
Facing weird type errors? You aren't alone. This is the hardest part of using TypeScript with React. Be patient - you are learning...
Read more >
Getting Started with Typescript with React: 4 Easy Steps
npm install --save-dev typescript ts-loader @types/react ... the js files to tsx if they have React code, else ts and fix the entry...
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