0

I want to know how Redux generates its typings.

I'm still getting into typescript because I want the ability to generate a typings file that is understood by VSCode.

Redux's approach is perfect for my needs but I'm cunfused on how they generate the index.d.ts in their root directory.

  • 1
    Possible duplicate of [How do you produce a .d.ts "typings" definition file from an existing JavaScript library?](https://stackoverflow.com/questions/12687779/how-do-you-produce-a-d-ts-typings-definition-file-from-an-existing-javascript) – michaeln Apr 15 '19 at 11:13

2 Answers2

0

I briefly checked redux repo. Whole library is written in vanilla javascript, with a jsdoc at some places. It means that d.ts file could be generated based on jsdoc. Or (more likely) the file was written by hand.

  • They have typescript in their test folder. Can that generate it? – Anthony White Apr 12 '19 at 13:57
  • function typing is closely connected to the implementation itself. When you write your code in typescript you can tell the compiler: hey when you will transpile my code to the javascript please generate definitions for the functions. Or if code is written in javascript you have to define the types for that inside definition file (d.ts) – Pavel Kratochvil Apr 12 '19 at 14:25
  • I've been researching and I've probably found the answer: https://www.npmjs.com/package/tsd-jsdoc – Anthony White Apr 16 '19 at 12:16
0

Their index.d.ts isn't generated, it is hand-written. I still remember for quite some time people just have to use @types/redux. Then the core team took it seriously and started to maintain the typings inside the core repo. You can check the file history to see how it evolves.

hackape
  • 18,643
  • 2
  • 29
  • 57