Skip to content

Commit

Permalink
Fix (most) TypeScript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1eef committed Aug 31, 2024
1 parent 105b7b1 commit 21263d4
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 37 deletions.
1 change: 0 additions & 1 deletion Rules
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
tidy = `which tidy || which tidy5`.chomp
buildenv = ENV["buildenv"] || "development"
etcdir = File.join(__dir__, "etc")
globals = {buildenv:, locales:, tidy:, tdata:, surahs:, name_by_id:}

##
Expand Down
1 change: 1 addition & 0 deletions etc/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AllCops:
TargetRubyVersion: 3.2
Exclude:
- submodules/**/*
- source/**/*
Include:
- Rakefile.rb
- rake/tasks/*.rake
Expand Down
8 changes: 6 additions & 2 deletions etc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"include": ["../src/**/*.ts", "../src/**/*.tsx"],
"include": [
"../src/js/typings/globals.d.ts",
"../src/**/*.ts",
"../src/**/*.tsx",
],
"exclude": ["../node_modules"],
"compilerOptions": {
"strict": true,
Expand All @@ -8,7 +12,7 @@
"noImplicitAny": true,
"moduleResolution": "node",
"esModuleInterop": true,
"jsx": "react",
"jsx": "react-jsx",
"lib": [ "ES2020", "DOM" ],

"baseUrl": "../src/",
Expand Down
4 changes: 4 additions & 0 deletions etc/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module.exports = {
"@css": path.resolve(__dirname, "..", "src", "css"),
"@json": path.resolve(__dirname, "..", "src", "json"),
"~": 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"],
},
Expand Down
54 changes: 38 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
},
"dependencies": {
"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": {
"@types/css-font-loading-module": "^0.0.13",
"@types/react": "^18.0",
"@types/react-dom": "^18.0",
"@types/react": "^18.3.5",
"css-loader": "^7.1",
"esbuild-loader": "^4.1",
"eslint": "^9.8",
Expand Down
16 changes: 12 additions & 4 deletions src/js/components/Select/Option.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
type Rest = AnchorHTMLAttributes<HTMLAnchorElement>;
import type { ReactNode } from "preact/compat";

type Props = {
value: string;
href?: string | undefined;
className?: string;
onClick?: () => void;
children: ReactNode;
} & Rest;
};

export function Option({ children, ...rest }: Props) {
return <a {...rest}>{children}</a>;
export function Option({ children, href, className, onClick }: Props) {
return (
<a href={href || "#"} className={className} onClick={onClick}>
{String(children)}
</a>
);
}
9 changes: 4 additions & 5 deletions src/js/components/SurahStream/Stream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ export function Stream({
>
{stream.map((ayah: Ayah) => {
return (
<li
key={ayah.id}
className="ayah fade mb-5"
>
<span className={classNames("flex h-8 items-center", {"mb-2": rtl})}>
<li key={ayah.id} className="ayah fade mb-5">
<span
className={classNames("flex h-8 items-center", { "mb-2": rtl })}
>
<AudioControl
hidden={!(isPaused || endOfStream)}
audio={new Audio()}
Expand Down
6 changes: 3 additions & 3 deletions src/js/loaders/SurahIndexLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { formatNumber } from "~/lib/t";
const progressBar: HTMLProgressElement = loader.querySelector("progress")!;
const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!;
postman(
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/vendor.js?v=${rev}`, { id: "0" }),
item.script(`/js/main/surah-index.js?v=${rev}`, { id: "1" }),
item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)"),
item.progress((percent: number) => {
progressBar.value = percent;
Expand All @@ -35,7 +35,7 @@ import { formatNumber } from "~/lib/t";
pkg.fonts.forEach((f) => document.fonts.add(f));
pkg.css.forEach((s) => document.head.appendChild(s));
pkg.scripts
.sort((s) => s.id)
.sort((s) => Number(s.id))
.forEach((s) => {
document.body.removeChild(document.body.appendChild(s));
});
Expand Down
6 changes: 3 additions & 3 deletions src/js/loaders/SurahStreamLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { formatNumber } from "~/lib/t";
const progressBar = loader.querySelector("progress")!;
const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!;
postman(
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/vendor.js?v=${rev}`, { id: "0" }),
item.script(`/js/main/surah-stream.js?v=${rev}`, { id: "1" }),
item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)"),
/* eslint-disable */
item.json(`/json/${doc.lang}/${surahId}/info.json?v=${rev}`, { className: "json surahinfo" }),
Expand All @@ -42,7 +42,7 @@ import { formatNumber } from "~/lib/t";
pkg.css.forEach((s) => document.head.appendChild(s));
pkg.json.forEach((o) => document.body.appendChild(o));
pkg.scripts
.sort((s) => s.id)
.sort((s) => Number(s.id))
.forEach((s) => {
document.body.removeChild(document.body.appendChild(s));
});
Expand Down
11 changes: 11 additions & 0 deletions src/js/typings/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as preact from "preact";
import * as hooks from "preact/hooks";
import fn from "classnames";

Check failure on line 3 in src/js/typings/globals.d.ts

View workflow job for this annotation

GitHub Actions / ci

'fn' is defined but never used

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;
}

0 comments on commit 21263d4

Please sign in to comment.