Fix `getting-started.tsx` type check
See original GitHub issueBug 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:
- Created a year ago
- Reactions:2
- Comments:6 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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, whiletsc
runs with configuration fromtsconfig.json
. Docs - tsc CLI Options docs.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.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.