Skip to content

Update TypeScript config (and fix vitamin type)#222

Open
Hyperseeker wants to merge 5 commits intonornagon:mainfrom
Hyperseeker:update-typescript-config
Open

Update TypeScript config (and fix vitamin type)#222
Hyperseeker wants to merge 5 commits intonornagon:mainfrom
Hyperseeker:update-typescript-config

Conversation

@Hyperseeker
Copy link
Copy Markdown

Overview

This PR brings the app's TypeScript version to the latest stable value, and updates the associated packages to enable this. TypeScript was bumped because my IDE complained about outdated options and deprecations; the other packages were bumped to bring them in line with the expected TS version (all updated packages now use at least TS v5), as they were causing other issues with the config.

The overall impact of this PR is: it brings the codebase closer to modern standards, while eliminating outdated issues (and the bandaids that kept everything from falling apart), thus improving the DX for future developers and maintainers.

Secondary changes

By way of fixing other resulting issues, this PR also updates the type of Vitamin.rate to bring it in line with the code, rather than make the code follow the types. I believe earlier implementations of vitamins used numerical values, rather than quantity strings, for duration. The changes in this PR enable further support for very old versions of the game in HHG. (Whether this is really necessary is worth discussing; I'm open to reverting this change.)

It's also worth noting that in the current codebase of DDA, rate has a default value of "0 m"; this would make it optional in TypeScript. As such, even if supporting numerical vitamin rates is not a priority, rate should be marked as optional. All current vitamins have rate present and a quantity string, but that doesn't mean the value will always be present for all sources (including any potential future support for mods).

Aside from this, Vitamin.svelte and ComestibleInfo.svelte saw changes to both handle the updated type and guard against the possible value of 0 (and the resulting displayed value of Infinity).

Testing

Ran the dev server locally, searched a few things using default parameters (latest experimental, ASCII tileset, English language). Did not run the tests because they would take 10+ mins per, and I believe the manual testing (see below) should suffice.

Note that it's basically impossible to find these in the UI: they don't show up in default search, and are only reacheable through their associated items or by manipulating the URL. I've only tested the ones with unique values (most vitamins have decay rates of 15 m or 1 h).

calcium: decay rate of –1 / 15 m localhost_5173_vitamin_calcium
vit_betablocker: decay rate of –1 / 100 s localhost_5173_vitamin_calcium (1)
bad_food: decay rate of –1 / 4 h localhost_5173_vitamin_calcium (2)
blood: generation rate of 1 / 6 s localhost_5173_vitamin_blood

"isolatedModules": true,
"strict": true,
"ignoreDeprecations": "5.0"
"noEmit": true
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why these changes? noEmit: true seems in particular an odd change here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noEmit is to make TypeScript (correctly) believe it's only there for typechecking. You already bundle everything with Vite. TypeScript's had an issue with an .mjs file, which was considered both a source and a target (because it's a JS file, not a TS file). noEmit makes sure TypeScript doesn't have to think about these things.

ignoreDeprecations was the band-aid I mentioned in the PR body: it meant being able to stick to TypeScript v4 for longer, despite it being not the best idea. Removing it means you have to face the changes from v5 (which is about time, since v6 has already been published in beta, and v7 is available in the preview). This is also why I had to make the vitamin changes, which were otherwise hidden by some of the looser handling.

Everything else naturally propagates to the project from Svelte's TypeScript config.

@Hyperseeker
Copy link
Copy Markdown
Author

Updated rateAbsDisplay to correctly use rateSec, since we already compute it. It was my bad for missing that on the first try. Note that this also meant updating asHumanReadableDuration() to return space-separated unit pairs (e.g. 3 h, not 3h), to align with the game's own data format and, subsequently, with the latest deployed version of the HHG.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants