-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
Typescript type definitions #431
Comments
Yeah would nice to see this public thank you. |
Very much so! We have also made private type definitions for our internal use case but they are also incomplete. Would be great to finally see a public type definition. I'm up to help out with PRs later. |
My current state is at https://github.com/DanielRose/DefinitelyTyped/tree/socketcluster There are type definitions for sc-auth, socketcluster, socketcluster-client and socketcluster-server. It is still incomplete, especially missing tests (except for sc-auth). |
@DanielRose We should link to it from the project website :) |
@jondubois Once it is in a somewhat releasable state, I'll send a PR. I'm currently expanding the code by adding expirymanager, fleximap, sc-broker, sc-broker-cluster and adding additional methods and so on. |
I now have a version that throws no errors when compiling for DefinitelyTyped. I have the type definitions (though incomplete in some places) for:
Please take a look. If nobody complains I'll send a PR in the next days. |
@DanielRose thanks for types! I tried it out like this:
I am not sure whether problem is in setup of DefinitelyTyped or types themselves, so here's the steps to reproduce and please let me know! |
I copied But I have a error in SocketCluster's own example
|
@Akuukis typeRoots is deprecated. It is a relic from TypeScript v1 (or something like that) and doesn't work with modern type definitions. The correct way to add custom type definitions is via the combination of baseUrl and paths, i.e. {
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": ["src/types/*"]
}
}
} Note that by convention, the type definitions in I've updated the type definitions to add attach and listen. |
@DanielRose Thanks, that worked. Types looks good so far. Can you please also type |
sc-uws is basically the same as uws. Unfortunately the type definitions there are not up to date. I could work on them later, but first I would want to finish these. |
@DanielRose Right, sc-uws can be done seperately. In that case types looks good to me |
@DanielRose My current stance is that we shouldn't force developers to use TypeScript in order to use SocketCluster but also we don't want to discourage them from using it either. Would having all the type definitions in a folder directly inside this |
I have seen three cases:
Personally, when doing |
@Akuukis the second approach sounds good. I think that if we have the types in the main socketcluster repo, they'll be more likely to be kept up to date with the JS code. Also having a stub with warnings in DefinitelyTyped repo sounds good. |
Leaving aside how to get the .d.ts files (either autogenerated because the code is written in Typescript, or manually written), there are two main options, as @Akuukis wrote:
Advantage of bundling the type definitions:
Disadvantages:
|
@DanielRose we can go with whatever you think is best ;p We can mention the existence of the typescript definitions on the socketcluster.io website when ready. |
Sorry for ignorance... But could you provide how to get these types? Im not seeing them in any of the source. Thanks! |
apologies, I found the types, SCServer import worked when I threw them all in the node_modules/@types directory... But SCWorker is not? |
bump. @jondubois , what's the checklist to get types into the repo? |
@Akuukis I haven'ted used SC with TypeScript yet so I'm not sure what steps are involved so feel free to lead the way if you have something specific in mind. You can make a proposal here or as a new issue and if/when the community is generally happy with the proposal then you can make a PR. |
Sorry I've been absent for so long. I was on vacation, and then we had major production issues (hangs and crashes). I'll try to finish the PR in the next couple of days. |
Finally got everything done. Found a few places where I had wrong definitions or was missing them: DefinitelyTyped/DefinitelyTyped#30944 |
PR got merged! |
I've started with Typescript type definitions for some of the socketcluster libraries. They are currently in my private repository and incomplete. Is there any interest in this?
The text was updated successfully, but these errors were encountered: