wmonk / create-react-app-typescript

DEPRECATED: Create React apps using typescript with no build configuration.
3.7k stars 492 forks source link

Type definitions are not generated #262

Open dborysov opened 6 years ago

dborysov commented 6 years ago

Is this a bug report?

Yes

Can you also reproduce the problem with npm 4.x?

Yes

Which terms did you search for in User Guide?

declaration

Environment

  1. npm ls react-scripts-ts (if you haven’t ejected): 2.13.0
  2. node -v: v8.9.4
  3. npm -v: 5.6.0
  4. yarn --version (if you use Yarn): 1.3.2

Then, specify:

  1. Operating system: MacOS High Sierra
  2. Browser and version (if relevant): -

Steps to Reproduce

(Write your steps here:)

  1. npx create-react-app ourapp --scripts-version react-scripts-ts
  2. cd ourapp
  3. add "declaration": true, to the package.json and remove "allowJs": true,
  4. yarn build
  5. ls build/static/js

Expected Behavior

I should see .d.ts types declarations

Actual Behavior

I don't see .d.ts types declarations

DorianGrey commented 6 years ago

That doesn't work due to the bundling process, or at least the way it is configured atm.. Not specific to CRA(-ts), but to every project using typescript while bundling with webpack.

However, there are two ways to achieve what you want.

  1. Follow the instructions from the ts-loader README - but beware, since it requires adding a plugin, you'd have to eject: https://github.com/TypeStrong/ts-loader/blob/master/README.md#declarations-dts Benefit: Generates a single bundle containing your typings. Drawback: Requires ejecting; plugin does not seem to be that actively maintained.
  2. Generate them via npx tsc -p tsconfig.json --emitDeclarationOnly. The declarations will end up in build/dist (or whatever you changed outDir to) in hierachical structure. Benefit: Does not require ejecting, can be done without any additional tools. Drawback: It's not a bundle, but a collection of files.