Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@testing-library/svelte": "^3.0.3",
"@transifex/cli": "^4.2.4",
"@transifex/native": "^4.2.4",
"@tsconfig/svelte": "^2.0.1",
"@tsconfig/svelte": "^5",
"@types/gettext.js": "^1.0.0",
"@types/lodash.throttle": "^4.1.7",
"@types/node": "^14.14.31",
Expand All @@ -43,8 +43,8 @@
"prettier": "^2.3.2",
"prettier-plugin-svelte": "^2.4.0",
"svelte": "^3.58.0",
"svelte-check": "^2.2.7",
"svelte-preprocess": "^4.9.8",
"svelte-check": "^3.8.6",
"svelte-preprocess": "^5.1.4",
"ts-json-schema-generator": "^1.3.0-next.3",
"tslib": "^2.3.1",
"typescript": "~5",
Expand Down
2 changes: 1 addition & 1 deletion src/data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { writable } from "svelte/store";
import makeI18n, { Gettext } from "gettext.js";
import makeI18n, { type Gettext } from "gettext.js";

import {
type Translation,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ export type Vitamin = {
excess?: string; // effect_id
min?: number; // int
max?: number; // int, default 0
rate: string; // duration
rate?: duration; // default "0 m"
vit_type: "vitamin" | "toxin" | "drug" | "counter";
disease?: [number, number][];
disease_excess?: [number, number][];
Expand Down
24 changes: 14 additions & 10 deletions src/types/Vitamin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { t } from "@transifex/native";
import { getContext } from "svelte";
import {
CddaData,
asHumanReadableDuration,
normalizeUseAction,
parseDuration,
parseMass,
Expand All @@ -30,7 +31,14 @@ const mutationCategory = data
.byType("mutation_category")
.find((c) => c.vitamin === item.id);

const unitsPerDay = (24 * 60 * 60) / parseDuration(item.rate);
const rateSec = item.rate != null ? parseDuration(item.rate) : 0;
const unitsPerDay = rateSec !== 0 ? (24 * 60 * 60) / rateSec : 0;
const rateAbsDisplay =
item.rate != null
? typeof item.rate === "string"
? item.rate.replace(/-/, "")
: asHumanReadableDuration(Math.abs(item.rate))
: null;
const containingComestibles = data
.byType("item")
.filter(
Expand All @@ -44,7 +52,7 @@ const containingComestibles = data
const pctOrMass = comestible.vitamins!.find((v) => v[0] === item.id)![1];
const pct: number =
typeof pctOrMass !== "number"
? item.weight_per_unit
? item.weight_per_unit && unitsPerDay
? (parseMass(pctOrMass ?? "0 g") /
parseMass(item.weight_per_unit) /
unitsPerDay) *
Expand Down Expand Up @@ -125,16 +133,12 @@ const deficiencyNames = item.deficiency
<dd>{item.min ?? 0}</dd>
<dt>{t("Max", { _context })}</dt>
<dd>{item.max ?? 0}</dd>
{#if parseDuration(item.rate ?? "0 m") > 0}
{#if rateSec > 0}
<dt>{t("Decay Rate", { _context })}</dt>
<dd>–1 / {item.rate ?? "0 m"}</dd>
{:else if parseDuration(item.rate ?? "0 m") < 0}
<dd>–1 / {rateAbsDisplay}</dd>
{:else if rateSec < 0}
<dt>{t("Generation Rate", { _context })}</dt>
<dd>
1 / {typeof item.rate === "string"
? item.rate.replace(/-/, "")
: -(item.rate ?? 0) ?? "0 m"}
</dd>
<dd>1 / {rateAbsDisplay}</dd>
{/if}
{#if item.decays_into?.length}
<dt>{t("Decays Into", { _context })}</dt>
Expand Down
5 changes: 3 additions & 2 deletions src/types/item/ComestibleInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const data = getContext<CddaData>("data");
{@const massPerUnit = v.weight_per_unit
? parseMass(v.weight_per_unit)
: null}
{@const unitsPerDay = (24 * 60 * 60) / parseDuration(v.rate)}
{@const rateSec = parseDuration(v.rate ?? 0)}
{@const unitsPerDay = rateSec !== 0 ? (24 * 60 * 60) / rateSec : 0}
{@const mass =
typeof rdapct === "string"
? parseMass(rdapct)
Expand All @@ -71,7 +72,7 @@ const data = getContext<CddaData>("data");
{@const rda =
typeof rdapct === "number"
? rdapct
: mass && massPerUnit
: mass && massPerUnit && unitsPerDay
? (mass / massPerUnit / unitsPerDay) * 100
: null}
<dt>
Expand Down
6 changes: 1 addition & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"resolveJsonModule": true,
"baseUrl": ".",
/**
Expand All @@ -14,9 +12,7 @@
*/
"allowJs": true,
"checkJs": true,
"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.

},
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
Loading