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

Open
blakeembrey opened this Issue Mar 16, 2016 · 32 comments

Comments

@blakeembrey
Copy link
Contributor

blakeembrey commented Mar 16, 2016

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

bengreenier commented May 30, 2016

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

@mhegazy

This comment has been minimized.

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.

@endel

This comment has been minimized.

Copy link

endel commented Nov 3, 2016

This would be definitely helpful 👍

@trusktr

This comment has been minimized.

Copy link

trusktr commented Jan 24, 2017

👍

@bowdenk7

This comment has been minimized.

Copy link
Member

bowdenk7 commented Jan 25, 2017

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

This comment has been minimized.

Copy link
Contributor

blakeembrey commented Jan 25, 2017

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

This comment has been minimized.

Copy link
Contributor

MicahZoltu commented Mar 27, 2017

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

mhegazy commented May 10, 2017

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

@bengreenier

This comment has been minimized.

Copy link
Member

bengreenier commented May 12, 2017

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

@pmunin

This comment has been minimized.

Copy link

pmunin commented Sep 26, 2018

any updates on that? Current behavior is quite weird : I am using it with webpack 4.20, and webpack config has 2 configurations - development and production. So It actually DOES generate declarations bundle.d.ts and bundle.js itself but only for first configuration, then it throws error "TS5053" and does not even start second (production) configuration. So to point the elephant in the room - can it be fixed simply by changing TS5053 to a warning from error?

@amitbeck

This comment has been minimized.

Copy link

amitbeck commented Oct 25, 2018

This makes it really problematic to reference projects with a tsconfig.json which had --allowJs and now must use --declaration for it to work.

@sorenhoyer

This comment has been minimized.

Copy link

sorenhoyer commented Oct 26, 2018

We also just ran into this issue. Any status on how it's progressing? :-)

@nojvek

This comment has been minimized.

Copy link
Contributor

nojvek commented Nov 12, 2018

I’ll take another stab at the PR to deliver a MVP .js -> .d.ts types. We’ve converted a ton of things to .js with jsdoc types and this would be quite useful to the rest of the community.

@nickmccurdy

This comment has been minimized.

Copy link

nickmccurdy commented Nov 12, 2018

I think you can already do that with dts-gen, but it would be great to have the functionality in TypeScript itself.

@styfle

This comment has been minimized.

Copy link
Contributor

styfle commented Nov 12, 2018

@nickmccurdy It looks like dts-gen hasn't been updated in over a year and still uses TS 2.x

@weswigham

This comment has been minimized.

Copy link
Member

weswigham commented Nov 12, 2018

dts-gen is preferable for a certain set of people (and its functionality is now a quickfix in the compiler, which is why the standalone project isn't maintained so much) - it inspects the types it can find at runtime, and so can be pretty accurate with no annotations present. What this feature is for, I imagine, is people using mostly jsdoc to strongly type their JS, who want their documentation and types preserved and transformed into a public API.

@studds

This comment has been minimized.

Copy link

studds commented Nov 12, 2018

While generating types from javascript would be useful, is there a way to simply skip the javascript files when emitting types? Surely emitting some types is better than nothing at all.

@talhajunaidd

This comment has been minimized.

Copy link

talhajunaidd commented Dec 12, 2018

As a workaround, I used tsc to generate dist folder with allowJs: true in tsconfig.json and then used tsc -d --emitDeclarationOnly --allowJs false to generate typings in dist folder.

@TheLarkInn

This comment has been minimized.

Copy link
Member

TheLarkInn commented Dec 13, 2018

This would be very very nice to have as now that we have completely typed out our webpack configuration and types for our public api, exposing this on a single d.ts would mark a lot of progress for thrid party integrations and plugin authors. :-) <3 @DanielRosenwasser @weswigham :-)

@tangkunyin

This comment has been minimized.

Copy link

tangkunyin commented Jan 3, 2019

@talhajunaidd Thanks, It's work for me. Also I wrote a blog for those who want help:https://shuoit.net/tech-notes/Allow--declaration-with--allowJs-1546511333.html

@balupton

This comment has been minimized.

Copy link

balupton commented Jan 3, 2019

For what it is worth, I recently discovered over at
#29056 (comment)

That if a consumer sets maxNodeModuleJsDepth to say 5 in their tsconfig, then typescript is likely able to pickup the jsdoc types of the packages they consume automatically, without the need for any d.ts file. Which is likely a suitable workaround for many here.

I've updated https://github.com/bevry/projectz to automatically generate an installation guidance in readmes of maxNodeModuleJsDepth to 5 if the project it is running against has jsdoc in its dependencies.

The result of this generation can be seem on the caterpillar package for example:
https://github.com/bevry/caterpillar

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