Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Type definitions are not generated #262

Open
dborysov opened this issue Feb 23, 2018 · 1 comment
Open

Type definitions are not generated #262

dborysov opened this issue Feb 23, 2018 · 1 comment

Comments

@dborysov
Copy link

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
Copy link
Collaborator

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants