-
-
Notifications
You must be signed in to change notification settings - Fork 62
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 definitions file #92
Comments
Belatedly, saved as a gist to https://gist.github.com/JamesSkemp/d090ba39a53853841b8dc0ecc7d78887 Still in-progress but working pretty good in a private project I'm working on. More than willing to create a merge request with this if it would be helpful. |
Hi @JamesSkemp . I've not used Typescript myself yet, but am interested in it. I had a look at your Gist, seems interesting. Is it a case of listing everything that the library exports and what type it is? I'm happy to accept a pull request into the Thank you very much for the interest and help! Really appreciated. |
Awesome, thanks @GreenImp :) Yes, since TypeScript is a strongly-typed language, a definitions/declaration file helps with not only what the library provides for functionality, but also what types they accept and return, and then provides some nice type safety while writing code. I know the Phaser framework has some basic TypeScript tests, so it should be completely possible to do so. I've started a fork and have the types brought over, but don't have the simple test working yet, probably due to the namespace I'm using. I'll work on it over the next few days and create a merge request when it's in a working state. (I've been working with TypeScript for a few years, but this is my first time adding support to another library, so time estimate very approximate. :) ) |
Cheers. I would rather have code coverage if possible, but if it proves to be untestable then that's fair enough. |
Sorry for the delay on this, it's been difficult to find time for any personal projects over the last week and a half. :/ I have a branch - https://github.com/JamesSkemp/rpg-dice-roller/tree/typescript-defs-wip-1 - that I had put some code changes into (with the hope that once I figure things out I would cherry pick or otherwise redo the changes).
|
So the issue I'm running into is having node test the generated JavaScript. If I generate the JavaScript file and manually change the third line to the following, I'm still getting an import error with
|
Is it the import { DiceRoller, DiceRoll } from "../../types/index" What's the import error? And do you need to use the full filename, |
Sorry for the delay, it's been a crazy week. :( In all cases TypeScript works, but running the test with If I have
It generates
Which errors with
If I have
It generates
Which errors with
This makes sense since there's no JS in the types directory. However, if I manually change the tests.js to:
(so that it properly points to the index.js file in the src directory) and
Based upon searches ~two weeks ago, I'm wondering if I need to run/test these with Jasmine, instead of just node, since it sounds like this might be a limitation of node and |
Ah right. Yes, that bit about imports with Node makes sense. I'm not sure if it'll fix your problem, but Node doesn't currently work with ES6 module imports (That's coming soon, or you can use a flag to enable now: https://nodejs.org/api/esm.html#esm_enabling). So, the library compiles the stuff in the
If you're running the library through Node, you'll either need to enable es6 modules, or try running against the |
I was wrong. Jasmine is using the |
Hi @JamesSkemp I'm nots ure if you're still looking into this or not - I understand if other things have taken priority - but thought I'd let you know I'm almost done with a re-build of the parsing engine. The benifit though, is that I've replaced Jasmine with Jest. This works nicely with ES6 imports, so there's no longer a need to pre-compile, you can import the src files directly. You can take a look at the code in the |
I actually pulled this project back up when I restarted my computer the other day, so definitely still interested in using and writing defs for it. I'll read up on Jest and take a look at that branch this week. |
Ah, I also should have mentioned that, although the new rolling engine is on that branch, the replacing of Jasmine JS with Jest is actually on the |
I've come to the conclusion that I need to ask the community how to integrate these definitions in, since the main suggestions I see about using Jest (and other testing frameworks) relates more to projects that are completely written in TypeScript. From that, a user (keith) noted a mistake in the repo's summary/description field:
|
Ah good spot! That's what happens when I write documentation too late at night. |
Quick note that there is an interesting alternative: dice-typescript. But as another member of the community, I would also be interested in minimal typescript support. I wouldn't do it entirely by myself, but if more people are interested, I'd love to collaborate. |
Belatedly @ldd, do you have experience creating in-library TS defs? That and actually testing the defs (which I'm not sure is even possible - they should either work or not) is where this is stalled. |
Update: Due to microsoft/dts-gen#42, |
Thanks @JamesSkemp for your work. This has been merged and will go out in v4.2.0 |
Woohoo! |
This has been release now! |
Is your feature request related to a problem? Please describe.
No. This is an enhancement request.
Describe the solution you'd like
I recently discovered this library and would love to use it in a project that uses TypeScript. To best enable this it would be great if typings were available.
Describe alternatives you've considered
I plan on working on a TypeScript definition file for my own use, but if there's interest, think it would benefit this project if it were included.
Additional context
My plan is to create the initial TypeScript definitions via dts-gen (already done) and then update them based upon this project's actual documentation. I would then be testing it in my own project.
I understand that TypeScript definitions may not appeal to you, depending upon your own usage and target audience, and since it does require updating if the library changes, so not a big deal if you're not interested. Just want to gauge if there's interest as that will determine how much effort I put into this.
Thanks for the great library!
The text was updated successfully, but these errors were encountered: