Fix (most) TypeScript errors

This commit is contained in:
0x1eef 2024-08-31 00:25:04 -03:00
parent 105b7b18cb
commit 21263d4574
11 changed files with 87 additions and 37 deletions

1
Rules
View file

@ -24,7 +24,6 @@ tdata = Ryo.from_json(path: File.join(dirs.content, "json", "t.json"))
surahs = Ryo.from_json(path: File.join(dirs.content, "json", "surahs.json")) surahs = Ryo.from_json(path: File.join(dirs.content, "json", "surahs.json"))
tidy = `which tidy || which tidy5`.chomp tidy = `which tidy || which tidy5`.chomp
buildenv = ENV["buildenv"] || "development" buildenv = ENV["buildenv"] || "development"
etcdir = File.join(__dir__, "etc")
globals = {buildenv:, locales:, tidy:, tdata:, surahs:, name_by_id:} globals = {buildenv:, locales:, tidy:, tdata:, surahs:, name_by_id:}
## ##

View file

@ -4,6 +4,7 @@ AllCops:
TargetRubyVersion: 3.2 TargetRubyVersion: 3.2
Exclude: Exclude:
- submodules/**/* - submodules/**/*
- source/**/*
Include: Include:
- Rakefile.rb - Rakefile.rb
- rake/tasks/*.rake - rake/tasks/*.rake

View file

@ -1,5 +1,9 @@
{ {
"include": ["../src/**/*.ts", "../src/**/*.tsx"], "include": [
"../src/js/typings/globals.d.ts",
"../src/**/*.ts",
"../src/**/*.tsx",
],
"exclude": ["../node_modules"], "exclude": ["../node_modules"],
"compilerOptions": { "compilerOptions": {
"strict": true, "strict": true,
@ -8,7 +12,7 @@
"noImplicitAny": true, "noImplicitAny": true,
"moduleResolution": "node", "moduleResolution": "node",
"esModuleInterop": true, "esModuleInterop": true,
"jsx": "react", "jsx": "react-jsx",
"lib": [ "ES2020", "DOM" ], "lib": [ "ES2020", "DOM" ],
"baseUrl": "../src/", "baseUrl": "../src/",

View file

@ -7,6 +7,10 @@ module.exports = {
"@css": path.resolve(__dirname, "..", "src", "css"), "@css": path.resolve(__dirname, "..", "src", "css"),
"@json": path.resolve(__dirname, "..", "src", "json"), "@json": path.resolve(__dirname, "..", "src", "json"),
"~": path.resolve(__dirname, "..", "src", "js"), "~": path.resolve(__dirname, "..", "src", "js"),
"react": "preact/compat",
"react-dom/test-utils": "preact/test-utils",
"react-dom": "preact/compat",
"react/jsx-runtime": "preact/jsx-runtime",
}, },
extensions: [".js", ".ts", ".tsx", ".json", ".css", ".scss"], extensions: [".js", ".ts", ".tsx", ".json", ".css", ".scss"],
}, },

54
package-lock.json generated
View file

@ -10,12 +10,14 @@
], ],
"dependencies": { "dependencies": {
"classnames": "^2.3", "classnames": "^2.3",
"preact": "^10.23.2" "preact": "^10.23.2",
"react": "npm:@preact/compat",
"react-dom": "npm:@preact/compat",
"react-jsxruntime": "npm:@preact/compat"
}, },
"devDependencies": { "devDependencies": {
"@types/css-font-loading-module": "^0.0.13", "@types/css-font-loading-module": "^0.0.13",
"@types/react": "^18.0", "@types/react": "^18.3.5",
"@types/react-dom": "^18.0",
"css-loader": "^7.1", "css-loader": "^7.1",
"esbuild-loader": "^4.1", "esbuild-loader": "^4.1",
"eslint": "^9.8", "eslint": "^9.8",
@ -714,9 +716,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/react": { "node_modules/@types/react": {
"version": "18.3.4", "version": "18.3.5",
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.4.tgz", "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.5.tgz",
"integrity": "sha512-J7W30FTdfCxDDjmfRM+/JqLHBIyl7xUIp9kwK637FGmY7+mkSFSe6L4jpZzhj5QMfLssSDP4/i75AKkrdC7/Jw==", "integrity": "sha512-WeqMfGJLGuLCqHGYRGHxnKrXcTitc6L/nBUWfWPcTarG3t9PsquqUMuVeXZeca+mglY4Vo5GZjCi0A3Or2lnxA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -724,16 +726,6 @@
"csstype": "^3.0.2" "csstype": "^3.0.2"
} }
}, },
"node_modules/@types/react-dom": {
"version": "18.3.0",
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.0.tgz",
"integrity": "sha512-EhwApuTmMBmXuFOikhQLIBUn6uFg81SwLMOAUgodJF14SOBOCMdU04gDoYi0WOJJHD144TL32z4yDqCW3dnkQg==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/react": "*"
}
},
"node_modules/@typescript-eslint/eslint-plugin": { "node_modules/@typescript-eslint/eslint-plugin": {
"version": "8.2.0", "version": "8.2.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.2.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.2.0.tgz",
@ -3336,6 +3328,36 @@
"safe-buffer": "^5.1.0" "safe-buffer": "^5.1.0"
} }
}, },
"node_modules/react": {
"name": "@preact/compat",
"version": "17.1.2",
"resolved": "https://registry.npmjs.org/@preact/compat/-/compat-17.1.2.tgz",
"integrity": "sha512-7pOZN9lMDDRQ+6aWvjwTp483KR8/zOpfS83wmOo3zfuLKdngS8/5RLbsFWzFZMGdYlotAhX980hJ75bjOHTwWg==",
"license": "MIT",
"peerDependencies": {
"preact": "*"
}
},
"node_modules/react-dom": {
"name": "@preact/compat",
"version": "17.1.2",
"resolved": "https://registry.npmjs.org/@preact/compat/-/compat-17.1.2.tgz",
"integrity": "sha512-7pOZN9lMDDRQ+6aWvjwTp483KR8/zOpfS83wmOo3zfuLKdngS8/5RLbsFWzFZMGdYlotAhX980hJ75bjOHTwWg==",
"license": "MIT",
"peerDependencies": {
"preact": "*"
}
},
"node_modules/react-jsxruntime": {
"name": "@preact/compat",
"version": "17.1.2",
"resolved": "https://registry.npmjs.org/@preact/compat/-/compat-17.1.2.tgz",
"integrity": "sha512-7pOZN9lMDDRQ+6aWvjwTp483KR8/zOpfS83wmOo3zfuLKdngS8/5RLbsFWzFZMGdYlotAhX980hJ75bjOHTwWg==",
"license": "MIT",
"peerDependencies": {
"preact": "*"
}
},
"node_modules/readdirp": { "node_modules/readdirp": {
"version": "3.6.0", "version": "3.6.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",

View file

@ -10,12 +10,14 @@
}, },
"dependencies": { "dependencies": {
"classnames": "^2.3", "classnames": "^2.3",
"preact": "^10.23.2" "preact": "^10.23.2",
"react": "npm:@preact/compat",
"react-dom": "npm:@preact/compat",
"react-jsxruntime": "npm:@preact/compat"
}, },
"devDependencies": { "devDependencies": {
"@types/css-font-loading-module": "^0.0.13", "@types/css-font-loading-module": "^0.0.13",
"@types/react": "^18.0", "@types/react": "^18.3.5",
"@types/react-dom": "^18.0",
"css-loader": "^7.1", "css-loader": "^7.1",
"esbuild-loader": "^4.1", "esbuild-loader": "^4.1",
"eslint": "^9.8", "eslint": "^9.8",

View file

@ -1,9 +1,17 @@
type Rest = AnchorHTMLAttributes<HTMLAnchorElement>; import type { ReactNode } from "preact/compat";
type Props = { type Props = {
value: string; value: string;
href?: string | undefined;
className?: string;
onClick?: () => void;
children: ReactNode; children: ReactNode;
} & Rest; };
export function Option({ children, ...rest }: Props) { export function Option({ children, href, className, onClick }: Props) {
return <a {...rest}>{children}</a>; return (
<a href={href || "#"} className={className} onClick={onClick}>
{String(children)}
</a>
);
} }

View file

@ -37,11 +37,10 @@ export function Stream({
> >
{stream.map((ayah: Ayah) => { {stream.map((ayah: Ayah) => {
return ( return (
<li <li key={ayah.id} className="ayah fade mb-5">
key={ayah.id} <span
className="ayah fade mb-5" className={classNames("flex h-8 items-center", { "mb-2": rtl })}
> >
<span className={classNames("flex h-8 items-center", {"mb-2": rtl})}>
<AudioControl <AudioControl
hidden={!(isPaused || endOfStream)} hidden={!(isPaused || endOfStream)}
audio={new Audio()} audio={new Audio()}

View file

@ -18,8 +18,8 @@ import { formatNumber } from "~/lib/t";
const progressBar: HTMLProgressElement = loader.querySelector("progress")!; const progressBar: HTMLProgressElement = loader.querySelector("progress")!;
const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!; const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!;
postman( postman(
item.script(`/js/main/vendor.js?v=${rev}`, { id: 0 }), item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }),
item.script(`/js/main/surah-index.js?v=${rev}`, { id: 1 }), item.script(`/js/main/surah-index.js?v=${rev}`, { id: "1" }),
item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)"), item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)"),
item.progress((percent: number) => { item.progress((percent: number) => {
progressBar.value = percent; progressBar.value = percent;
@ -35,7 +35,7 @@ import { formatNumber } from "~/lib/t";
pkg.fonts.forEach((f) => document.fonts.add(f)); pkg.fonts.forEach((f) => document.fonts.add(f));
pkg.css.forEach((s) => document.head.appendChild(s)); pkg.css.forEach((s) => document.head.appendChild(s));
pkg.scripts pkg.scripts
.sort((s) => s.id) .sort((s) => Number(s.id))
.forEach((s) => { .forEach((s) => {
document.body.removeChild(document.body.appendChild(s)); document.body.removeChild(document.body.appendChild(s));
}); });

View file

@ -19,8 +19,8 @@ import { formatNumber } from "~/lib/t";
const progressBar = loader.querySelector("progress")!; const progressBar = loader.querySelector("progress")!;
const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!; const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!;
postman( postman(
item.script(`/js/main/vendor.js?v=${rev}`, { id: 0 }), item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }),
item.script(`/js/main/surah-stream.js?v=${rev}`, { id: 1 }), item.script(`/js/main/surah-stream.js?v=${rev}`, { id: "1" }),
item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)"), item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)"),
/* eslint-disable */ /* eslint-disable */
item.json(`/json/${doc.lang}/${surahId}/info.json?v=${rev}`, { className: "json surahinfo" }), item.json(`/json/${doc.lang}/${surahId}/info.json?v=${rev}`, { className: "json surahinfo" }),
@ -42,7 +42,7 @@ import { formatNumber } from "~/lib/t";
pkg.css.forEach((s) => document.head.appendChild(s)); pkg.css.forEach((s) => document.head.appendChild(s));
pkg.json.forEach((o) => document.body.appendChild(o)); pkg.json.forEach((o) => document.body.appendChild(o));
pkg.scripts pkg.scripts
.sort((s) => s.id) .sort((s) => Number(s.id))
.forEach((s) => { .forEach((s) => {
document.body.removeChild(document.body.appendChild(s)); document.body.removeChild(document.body.appendChild(s));
}); });

11
src/js/typings/globals.d.ts vendored Normal file
View file

@ -0,0 +1,11 @@
import * as preact from "preact";
import * as hooks from "preact/hooks";
import fn from "classnames";
declare global {
const render: typeof preact.render;
const useState: typeof hooks.useState;
const useEffect: typeof hooks.useEffect;
const useRef: typeof hooks.useRef;
const useMemo: typeof hooks.useMemo;
}