3

I can't seem to get my create-react-app with typescript to generate declaration files. A .d.ts file should be added to the build folder when building. Adding "declaration": true to the tsconfig.json didn't change it. To reproduce create a new app with npx create-react-app --template typescript and build it with yarn build.

I also tried npx tsc --declaration and npx tsc --declarationOnly and didn't get the file either.

How would I get a new or already existing create-react-app to generate a .d.ts declaration file upon building?

Edit: I declaration files, because this project can be used as a library.

Shoggomo
  • 137
  • 8
  • 1
    I think I don't understand your question. Why do you want a d.ts file in your build folder? The browser doesn't understand typescript only javascript. – Karlan Aug 18 '20 at 11:48
  • 1
    @Karlan see edit. The project can be used as a library. That's why I need the declaration files. – Shoggomo Aug 18 '20 at 11:51
  • 1
    What I understand of it, create react app is not really made for publishing components to npm as a library. See https://create-react-app.dev/docs/deployment/#publishing-components-to-npm (scroll to the end). Maybe this article can help you: https://medium.com/@carlosthe19916/create-react-app-cra-and-publish-your-library-components-to-npm-typescript-storybook-67ff8fe1599e – Karlan Aug 18 '20 at 12:33

0 Answers0