Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow --declaration with --allowJs #7546

Closed
blakeembrey opened this issue Mar 16, 2016 · 60 comments · Fixed by #32372
Closed

Allow --declaration with --allowJs #7546

blakeembrey opened this issue Mar 16, 2016 · 60 comments · Fixed by #32372
Labels
Committed The team has roadmapped this issue Domain: JavaScript The issue relates to JavaScript specifically Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue

Comments

@blakeembrey
Copy link
Contributor

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.

@mhegazy mhegazy added Suggestion An idea for TypeScript Help Wanted You can do this labels Mar 16, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Mar 16, 2016

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,

@bengreenier
Copy link

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

@mhegazy
Copy link
Contributor

mhegazy commented Jun 1, 2016

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

got for it.

@waderyan waderyan added the VS Code Tracked There is a VS Code equivalent to this issue label Sep 14, 2016
@endel
Copy link

endel commented Nov 3, 2016

This would be definitely helpful 👍

@trusktr
Copy link
Contributor

trusktr commented Jan 24, 2017

👍

@bowdenk7
Copy link

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!

@blakeembrey
Copy link
Contributor Author

Thanks @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.

@MicahZoltu
Copy link
Contributor

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.

@nojvek
Copy link
Contributor

nojvek commented May 10, 2017

@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.

@mhegazy mhegazy modified the milestones: TypeScript 2.4, Community May 10, 2017
@mhegazy mhegazy added Committed The team has roadmapped this issue Salsa labels May 10, 2017
@mhegazy
Copy link
Contributor

mhegazy commented May 10, 2017

Based on the discussion in #15747, we would like to take this change.

@bengreenier
Copy link

@nojvek i've also made no more progress 😁 - got pulled into a different project and had to re-prioritize.

@industrialCoder
Copy link

industrialCoder commented Sep 4, 2019

@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....

@amitbeck
Copy link

amitbeck commented Sep 4, 2019 via email

@paralin
Copy link

paralin commented Sep 4, 2019

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

@rbiggs
Copy link

rbiggs commented Sep 5, 2019

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.

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Sep 5, 2019

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

@nomcopter
Copy link

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

@yin
Copy link
Contributor

yin commented Jan 3, 2020

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

@ljharb
Copy link
Contributor

ljharb commented Jan 3, 2020

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

@yin
Copy link
Contributor

yin commented Jan 4, 2020

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

@cecetipoi
Copy link

is this resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Committed The team has roadmapped this issue Domain: JavaScript The issue relates to JavaScript specifically Suggestion An idea for TypeScript VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet