Docusaurus: [v2] Usage with TypeScript

Created on 9 Sep 2020  路  6Comments  路  Source: facebook/docusaurus

馃悰 Bug Report

Regression of https://github.com/facebook/docusaurus/issues/2675

To Reproduce

npx @docusaurus/init@next init my-website classic

Follow steps https://v2.docusaurus.io/docs/typescript-support#setup.

Rename src/pages/index.js to src/pages/index.tsx.

VSCode displays the following errors:

  • Cannot find module '@docusaurus/Link' or its corresponding type declarations.
  • Cannot find module '@docusaurus/useDocusaurusContext' or its corresponding type declarations
  • Cannot find module '@docusaurus/useBaseUrl' or its corresponding type declarations.
  • Cannot find module './styles.module.css' or its corresponding type declarations.

Your Environment

  • Docusaurus version used: 2.0.0-alpha.63
  • Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): Node v12.18.3
  • Operating system and version (desktop or mobile): OSX v10.15.6
bug needs triage

Most helpful comment

this problem still appears to exist. Probably because the classic template doesn't have a tsconfig or anything. However, the tutorial that tells you that you can just use a tsx file if you want -uses the classic template and makes no mention of tsconfig

All 6 comments

Hey,

We are still figuring out how to provide the best TypeScript experience in Docusaurus, by trying to use it first on Docusaurus 2 site itself.

@SamChou19815 has done some initial work, and you could probably get started by using a src/types.d.ts file containing:

/// <reference types="@docusaurus/module-type-aliases" />
/// <reference types="@docusaurus/theme-classic" />

We don't have much TS code in our website yet, but hopefully we'll migrate over time and be able to recommend a good TS setup to our users.

I like how CRA works. Including a TypeScript template in the init would be awesome.

Adding the src/types.d.ts didn't work.

The @docusaurus/module-type-aliases is outdated on npm (2.0.0-alpha.51). It doesn't declare those modules.

https://github.com/facebook/docusaurus/blob/v2.0.0-alpha.51/packages/docusaurus-module-type-aliases/src/index.d.ts

It has since been updated but not published to npm. Can someone publish?
https://github.com/facebook/docusaurus/blob/33ecc4bb1750ab00841b0dfeaee525e9f9d89498/packages/docusaurus-module-type-aliases/src/index.d.ts

I see, if you install it at the correct version it works. yarn add -D @docusaurus/[email protected]

Initializing a TS site is definitively something we want, and contributions are welcome (but this does not seem like an easy one as it requires more general better TS support)

But what we want more is i18n support and get out of alpha asap ;)

About packages, that's unfortunate that an alpha has been published as "current", you should install package with @next anyway, but hopefully this will be solved automatically when we move out of alpha ;)

this problem still appears to exist. Probably because the classic template doesn't have a tsconfig or anything. However, the tutorial that tells you that you can just use a tsx file if you want -uses the classic template and makes no mention of tsconfig

Was this page helpful?
0 / 5 - 0 ratings

Related issues

azu picture azu  路  3Comments

JoelMarcey picture JoelMarcey  路  3Comments

itelofilho picture itelofilho  路  3Comments

NikitaIT picture NikitaIT  路  3Comments

omry picture omry  路  3Comments