-
Notifications
You must be signed in to change notification settings - Fork 106
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 conversion #175
Conversation
As of 51d2f94, I've also made a couple of important changes to please the type system (and us). I've added large blocks of comments to explain the reasons, in the code. @y-lohse, you'll certainly want to review this and tell me if it fits your vision for the project! InkList is now a MapIt makes the code closer to its C# counterpart, but comes with a tradeoff, since Javascript doesn't allow the creation of custom value-types (
|
Cool, thanks! I'll review this later on. In the meantime, I'd like to do some, to get the hang of it. So I'll take |
A bunch of general comments after trying some conversion myself:
|
I was looking into TypeScript the other day, I’m looking forward to seeing this go in! Are you planning to have full strict mode turned on? The non-nullables in particular have me quite excited :) |
Jinx, that was my intent. At the moment I'm mostly making everything public, but once the conversion is complete, I plan to make a pass on all classes and set the proper access control modifiers.
Do you want to remove the lint step from the build entirely, or do you mean that we should have an additional script handling the lint? I configured my editor so it's linting as-I-type, hence I never bothered creating a new npm script, but that's probably an oversight.
I just love that bit:
I guess Have you tried TypeScript is the new You should use React (Native) (probably even coming from the same folks on Twitter) 😂. I plead guilty on this one! I hold zero opinion on the matter, if you feel that we should keep If you mean |
Oh awesome! Very cool. |
I had completely forgotten about the typescript rant in the middle until after I posted the link haha 😁
I mean having an additional, separate step for linting. We can run it manually whenever we want to, and it would be run automatically by travis (and would block builds / releases). It makes sense to have both during the initial port to typescript, but when you're bug-hunting or quickly testing stuff, it's annoying as hell to get blocked by the linter when you just want a quick test run :) |
We could actually remove it altogether from the build script even during the conversion phase. It was perhaps a bit overzealous of me to add it in the first place, as I currently want to test something out and find myself prevented from doing so by the linter. I get it now 😀. |
As of 1ea543c, I've kept turning plain old regular Javascript object into Map where it made sense. Since I need to update some portion of the Javascript files as well, to keep the test running, it makes the process a bit more nerve-wrecking. But it's manageable. I didn't anticipate that I would need to do this in the first place, but it's definitely easier/better than defining interfaces for all the dictionaries or using Type cast / Type assertionI've also introduced the As said on #177,
I've organized these helpers as plain exported functions, but feel free to suggest another architecture. Debug.AssertI've also organized the Again, I didn't plan to implement all these things during the conversion. I made the mistake of not anticipating that that they would be required 😓. The migration diff is really hairy, as it combines simple type annotation with object-to-map / runtime casting changes. The diff will definitely be unmanageable as-is if @y-lohse wants to review line-by-line. Let me know if you want me to create another PR once it's completed and rebase all the changes in a one-file-per-commit fashion. |
I don't think the line by line review will be necessary (or doable :D), but the new security that typescript brings + the test suite gives me enough confidence that we won't ship anything broken. So it's only the "extras" like conversions to Maps, I'd like to merge this PR, and copy over the progress tracker and various informations to a new PR that would merge I'd like to do |
Convert Choice & ChoicePoint
I agree wholeheartedly, the current setup is a bit clumsy. I should probably have created a PR with the bare minimum and wait for you to merge it before iterating. I've merged your changes, so you can merge
Haha, yeah, Go ahead with these, I'll do all the little ones remaining in the meantime ( Edit: |
To be continued in #183 ! |
Tracking the TypeScript conversion.
The conversion is fairly straightforward, albeit time-consuming. I touch very little of the previous code, unless my hand is forced by the type system.
That said, I'm nonetheless converting
var
tolet
orconst
(depending on the context) and I'm also replacing.forEach
byfor of
loops (they're closer to their C# counterparts, they also allow returning early and Babel will take care of transpiling them).If anyone wants to contribute, pick a file, let me know about it and make a PR against
ephread/inkjs/typescript-conversion
(or if @y-lohse merge this PR, a PR againsty-lohse/inkjs/typescript
). Tests should keep passing after each commit.If the file have dependencies which haven't been converted yet, it's good practice to define the type as
any
and indicate the future type in a comment next to it (e. g. here).