Skip to content

Commit cd2db29

Browse files
authored
Merge pull request #22 from masonlet/chore/migrate-to-typescript
chore: migrate to typescript
2 parents d120e7a + cef172e commit cd2db29

38 files changed

Lines changed: 2523 additions & 345 deletions

.github/workflows/tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ jobs:
2222
- name: Install dependencies
2323
run: npm install
2424

25+
- name: Type check
26+
run: npm run typecheck
27+
2528
- name: Run tests
26-
run: npm test
29+
run: npm test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33

44
coverage/
55
node_modules/
6+
dist/
67

7-
.vercel
8+
.vercel

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ To get 10 languages, a dark theme, and a custom title:
8484

8585
### Prerequisites
8686
- Node.js 18+
87+
- TypeScript 5.0+
8788
- (Optional) Vercel or other Node.js hosting
8889

8990
### Installation
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import { parseQueryParams } from "../../src/utils/params.js";
1+
import { parseQueryParams, type QueryParams } from "../../src/utils/params.js";
22
import { fetchLanguageData, processLanguageData } from "../../src/api/github.js";
33
import { generateChartData } from "../../src/render/chart.js";
44
import { renderSvg } from "../../src/render/svg.js";
55
import { renderError } from "../../src/render/error.js";
6+
import type { VercelRequest, VercelResponse } from "@vercel/node";
67

7-
export default async function handler(req, res) {
8-
const params = parseQueryParams(req.query);
8+
export default async function handler(
9+
req: VercelRequest,
10+
res: VercelResponse
11+
): Promise<void> {
12+
const params = parseQueryParams(req.query as QueryParams);
913
const { chartType, chartTitle, width, height, count, selectedTheme, stroke, useTestData } = params;
1014

1115
try {
@@ -19,7 +23,7 @@ export default async function handler(req, res) {
1923
res.setHeader("Cache-Control", "public, max-age=3600, s-maxage=3600, stale-while-revalidate=60");
2024
res.status(200).send(svg);
2125
} catch (error) {
22-
const errorSvg = renderError(error.message, width, height, selectedTheme);
26+
const errorSvg = renderError((error as Error).message, width, height, selectedTheme);
2327
res.setHeader("Content-Type", "image/svg+xml");
2428
res.status(500).send(errorSvg);
2529
}

0 commit comments

Comments
 (0)