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

Add TypeScript declarations and generate docs #54

Closed
AlexTolmachev opened this issue Feb 10, 2019 · 23 comments
Closed

Add TypeScript declarations and generate docs #54

AlexTolmachev opened this issue Feb 10, 2019 · 23 comments
Labels
enhancement New feature or request

Comments

@AlexTolmachev
Copy link

Because of native nature of your library it's impossible for IDEs to list methods of req and res objects. Also it's impossible to get methods and properties of this objects via Object.enties or Object.keys.

So the question is where to find an uWS's HTTP API reference?

@xxzefgh
Copy link

xxzefgh commented Feb 10, 2019

If you understand a little bit of C++, you can explore wrapper headers. From a quick look, I can tell that HttpRequest has following methods:

getHeader
getParameter
getUrl
getMethod
getQuery

and HttpResponse:

writeStatus
end
tryEnd
write
writeHeader
close
getWriteOffset
onWritable
onAborted
onData

@ghost ghost added bug Something isn't working FAQ labels Feb 10, 2019
@ghost
Copy link

ghost commented Feb 10, 2019

What happens if you print res.prototype? Or res.prototype.entries etc?

@AlexTolmachev
Copy link
Author

My bad, forgot to take a look at the res's prototype 🧐

image

Anyway, I already used method described by @xxzefgh.

But I think, that for some js-developers it can be hard to even look at c++ source code :) So docs would be great addition to such a cool library 🤓

Thank you, guys!

@ghost
Copy link

ghost commented Feb 10, 2019

Printing res should print also the proto? Or? It would be nice.

@ghost
Copy link

ghost commented Feb 10, 2019

Adding typescript declarations would probably help a lot both documenting (TypeDoc) and for IDEs. How do I add that? I don't want third parties involved who cannot keep up

@ghost
Copy link

ghost commented Feb 10, 2019

I'm talking about definitelytyped - they don't care about quality just quantity

@ghost
Copy link

ghost commented Feb 10, 2019

Where do I put my d.ts file for best effect? Can I just ship it in the NPM package and be done?

@ghost
Copy link

ghost commented Feb 10, 2019

Oh I just create uws.d.ts and put types field in package.json and boom! Now the project is TypeScript wow.

A smart IDE will pick up that declaration file and apply to JavaScript as well yes?

@xxzefgh
Copy link

xxzefgh commented Feb 10, 2019

@alexhultman yes, either [filename].d.ts or index.d.ts will work.

@xxzefgh
Copy link

xxzefgh commented Feb 10, 2019

if you provide types or typings field in package.json, than anything will work I think

@ghost
Copy link

ghost commented Feb 10, 2019

Oh wow it works. Visual Studio Code did pick up on the index.d.ts in node_modules right away and shows exactly what is what. I love solutions like these, one file, compatible with JS, adds documentation too. 👍

@ghost
Copy link

ghost commented Feb 10, 2019

interface TemplatedApp {
z: number;
}

export function App(): TemplatedApp;

I want TemplateApp to have functions how do I achieve such a dream

@ghost
Copy link

ghost commented Feb 10, 2019

interface TemplatedApp {
listen(host: string, port: number): TemplatedApp;
}

export function App(): TemplatedApp;

There's no integer type?

@ghost ghost added enhancement New feature or request and removed FAQ bug Something isn't working labels Feb 10, 2019
@ghost ghost changed the title Where can I find docs on req and res objects? Add TypeScript declarations and generate docs Feb 10, 2019
@ghost
Copy link

ghost commented Feb 10, 2019

There are now documentation generated from decl file: https://github.com/uNetworking/uWebSockets.js/blob/master/docs/index.d.ts

WIP, but looks very beautiful!

@ghost
Copy link

ghost commented Feb 13, 2019

Documentation is pretty much done now, just need to have a release include that index.d.ts.

@ghost ghost closed this as completed Feb 13, 2019
@olivier65
Copy link

Please do consider uploading this stub to the DefinitelyTyped repository as well: https://github.com/DefinitelyTyped/DefinitelyTyped. That is where, e.g., the JetBrains IDEs look for them.

@ghost
Copy link

ghost commented Feb 25, 2020

You don't need to upload them to third party, definitions are shipped with the module. Visual studio code pick up on them

@olivier65
Copy link

If you prefer to include the definitions with the module then you should include a "types": "./index.d.ts" entry in your package.json to tell tools where to look for it. These are the only two standard ways to publish your definitions: see here.

It's possible VS Code goes beyond the call of duty and additionally looks for index.d.ts under the root but you can't expect every IDE to emulate VS Code.

@mikeandtherest
Copy link

Hi Alex.

I'm on VS Code using node 12+ with TS, but for some reason the IDE does not see the type definitions. I tried to manually reference them via /// <reference path="../node_modules/uWebSockets.js/index.d.ts" />, to no avail.

So I can confirm the need of what olivier65 and xxzefgh suggested, i.e. add the "types": "./index.d.ts" entry to the package.json file of the lib. I'm sure a lot of use would appreciate that. Thanks!

@ghost
Copy link

ghost commented Apr 22, 2020

If that helps can you PR it I forgot this issue

@ghost
Copy link

ghost commented May 17, 2020

"types": "./index.d.ts"

I added that line if it helps

@ghost
Copy link

ghost commented May 17, 2020

Is ./index.d.ts really Windows-compatible?

@ghost
Copy link

ghost commented May 17, 2020

I tested an older release on Windows / Visual Studio Code and it picked up on the type docs perfectly. According to the docs for package.json it should default to index.d.ts anyways.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants