reactjs - typescript ile react 18 oluştur react uygulaması


React 18 uygulamasını TypeScript ile oluşturmaya çalışıyorum, bu kılavuzu takip etmeyi denedim ama çalıştıramıyorum. tsconfig dosyasına "types": ["react/next", "react-dom/next"] ekleyemiyorum. Hata alıyorum:

Cannot find type definition file for 'react-dom/next'.
  The file is in the program because:
    Entry point of type library 'react-dom/next' specified in compilerOptionsts
Cannot find type definition file for 'react-dom/next'.
  The file is in the program because:
    Entry point of type library 'react-dom/next' specified in compilerOptionsts

Ayrıca 'react-dom/client'; üzerinden ReactDom'u içe aktaramıyorum, şu hatayı alıyorum:

Could not find a declaration file for module 'react-dom/client'. 'C:/Users/bansc/Desktop/youtube-channel/api-calls/my-app/node_modules/react-dom/client.js' implicitly has an 'any' type.
  If the 'react-dom' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-dom'ts(7016)

Cevap #1

Geçen hafta bunu çözmem çok uzun sürdü. react-dom experimental.d.ts dosyasında:

Burada bildirilen türleri gerçek bir projede yüklemek için üç yol vardır. En kolay yol, eğer tsconfig.json dosyanızın "compilerOptions" bölümünde zaten bir "types" dizisi varsa, "types" dizisine "react-dom/experimental" eklemektir.

Yani, bunu tsconfig.json dosyanıza ekleyin:

  "types" : [
    "react-dom/experimental"
  ]