Skip to content

Allow --declaration with --allowJs #7546

Description

From #7535, it would be useful for JavaScript package authors to have the ability to generate declarations from their project. This would help with getting started on a type definition (it would be populated with known interfaces/functions/types that are exported) and would also allow the creation of continuous integration scripts that check the JavaScript types with the hand-coded definition for inconsistencies.

Activity

  1. mhegazy commented on Mar 16, 2016

    @mhegazy
    Contributor

    PRs are welcomed. the fix should be removing the error, making sure the call is wired correctly, adding tests and making sure the declaration emitter handles the JS types correctly,

  2. added this to the milestone on Mar 16, 2016
  3. bengreenier commented on May 30, 2016

    @bengreenier

    anyone currently working on this? If not i may take a stab at it.

  4. mhegazy commented on Jun 1, 2016

    @mhegazy
    Contributor

    anyone currently working on this? If not i may take a stab at it.

    got for it.

  5. endel commented on Nov 3, 2016

    @endel

    This would be definitely helpful 👍

  6. trusktr commented on Jan 24, 2017

    @trusktr
    Contributor

    👍

  7. bowdenk7 commented on Jan 25, 2017

    @bowdenk7

    Take a look at dts-gen and let us know what you think. At the moment it doesn't do a good job of detecting changes between generations. But let us know if this helps!

  8. blakeembrey commented on Jan 25, 2017

    @blakeembrey
    ContributorAuthor

    Thanks Bowden Kelly (@bowdenk7)!

    Would a simple approach like #7535 (comment) (internally) be enough to check if the definition has changed? It would be great to be able to run dts-gen in CI and error when there has been un-documented API changes to prompt an update to the .d.ts.

  9. MicahZoltu commented on Mar 27, 2017

    @MicahZoltu

    Another use-case for this is that I have some plain JS tests that I use as both a form of documentation and as a way of validating that my code is callable from native ES5 in a way that is reasonable. All of my distributed source code is sourced from TypeScript and I would like to generate definition files for NPM publishing. However, because I have that one JS test sitting in my source tree I need allowJs=true so the test will correctly land in the output directory (not committed to source control) and be run along with all of my other tests. This, of course, means I can't have TSC output definition files for the rest of my project.

  10. nojvek commented on May 10, 2017

    @nojvek
    Contributor

    Ben Greenier (@bengreenier) Wondering if you have made much progress on this? Let me know if there is anyway I can help speed things up. Would love to see this out in the wild.

  11. 69 remaining items

  12. industrialCoder commented on Sep 2, 2019

    @industrialCoder
  13. studds commented on Sep 4, 2019

    @studds

    Wesley Wigham (@weswigham) Jordan Harband (@ljharb) - not trying to argue this isn't valuable, I'd have loved it when I needed it. Just trying to identify some other approaches.

    Ben Sawyer (@industrialCoder) would it be possible to change the rest of the files across to .ts and apply any yourself?

  14. industrialCoder commented on Sep 4, 2019

    @industrialCoder

    studds when I say a large legacy library, I mean a very large legacy library... The time it would take to convert all of the .js files over to .ts and add the syntax required to make them valid TS (even typing everything as any) would be obscene to say the least. Is saying type = importSourceType == js ? any : determineTSType(source) really that huge of a lift? Not familiar with the TS compiler code, but seems like this would be good bandaid solution that would help a lot of people out and should be much easier to implement than the solutions a lot of other people here are purposing....

  15. amitbeck commented on Sep 4, 2019

    @amitbeck
  16. paralin commented on Sep 4, 2019

    @paralin

    Amit Beckenstein (@amitbeck) I solved it for now by generating types separately and using --allowJs=false on the type generation step.

  17. rbiggs commented on Sep 5, 2019

    @rbiggs

    I have an issue opened on TypeScript problems with understanding imported JSDoc types from imported node modules. It's currently flagged as backlog. Feel free to comment there to push this along: #33136. Getting this fixed would allow JavaScript authors to provide JSDoc types for their code that end users could take advantage of for type linting and Intellisense in VSCode with allowjs set to true.

  18. OliverJAsh commented on Sep 5, 2019

    @OliverJAsh
    Contributor

    At Unsplash, this is blocking us from using project references aka composite (because composite requires declaration to be turned on).

  19. nomcopter commented on Sep 26, 2019

    @nomcopter

    Glorious day! Thanks Wesley Wigham (@weswigham)! Looks like this is slated for 3.7? Man that is going to be a great release.

  20. yin commented on Jan 3, 2020

    @yin
    Contributor

    Does the conversion mechanism recognize node packaging? It seems it generates one module per file, although Node.js exports one module per dependency.

  21. ljharb commented on Jan 3, 2020

    @ljharb
    Contributor

    A module is a file is a module; an npm package has 0, 1, or N files/modules.

  22. yin commented on Jan 4, 2020

    @yin
    Contributor

    You are right. Still, it does not help with producing declarations compatible with the node module lookup mechanism. You may want to refer to this question on StackOverflow for an example of what is precisely happening: https://stackoverflow.com/questions/59564524/generating-typescript-declarations-for-re-exported-js-functions-in-a-node-js-mod

  23. cecetipoi commented on Apr 15, 2021

    @cecetipoi

    is this resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CommittedThe team has roadmapped this issueDomain: JavaScriptThe issue relates to JavaScript specificallySuggestionAn idea for TypeScriptVS Code TrackedThere is a VS Code equivalent to this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions