Docusaurus: [v2] Usage with TypeScript

Created on 27 Apr 2020  ·  4Comments  ·  Source: facebook/docusaurus

🐛 Bug Report

I'm struggling to get TypeScript working with v2. The exported functionality which comes out of the box has a number of issues which are getting flagged. My IDE also complains about these when using standard JS but I can disable the inspection.

To Reproduce

npx @docusaurus/init@next init website

Rename pages/index.js to index.tsx.

I'm getting import errors, such as:

  • TS2307: Cannot find module '@docusaurus/useDocusaurusContext'.
  • TS2307: Cannot find module '@theme/Layout'.
    etc...

I can see within node_modules everything seems to be within the @docusaurus directory, but the exported types don't seem to be working.

Can someone point in in the right direction? Happy to start some docs, but I'm not entirely sure where to start.

bug needs triage

Most helpful comment

@SebastianM I successful resolved this error on the current public 58th alpha version flowing the steps below:

  1. read https://v2.docusaurus.io/docs/next/typescript-support/
  2. specify the new version of @docusaurus/module-type-aliases package explicitly at the first step:

    npm i -D @docusaurus/module-type-aliases@next ...other
    
  3. install @types/react if you use react hooks

All 4 comments

@Ehesp this issue should be fixed in v2.0.0-alpha.54. Please use that version. Sorry for that.

Sort of fixed - the @theme ones work, not the @docusaurus ones (see PR)

Latest version works, thanks.

@lex111 I still get this error with 2.0.0-alpha.58

@SebastianM I successful resolved this error on the current public 58th alpha version flowing the steps below:

  1. read https://v2.docusaurus.io/docs/next/typescript-support/
  2. specify the new version of @docusaurus/module-type-aliases package explicitly at the first step:

    npm i -D @docusaurus/module-type-aliases@next ...other
    
  3. install @types/react if you use react hooks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

awibox picture awibox  ·  3Comments

MoogyG picture MoogyG  ·  3Comments

chandankumar4 picture chandankumar4  ·  3Comments

endiliey picture endiliey  ·  3Comments

lex111 picture lex111  ·  3Comments