Skip to content

Commit fa48d89

Browse files
chore: upgrade to TypeScript 6 (#1146)
* build(deps): bump typescript to v6.0.2 * chore: add dts for external libs * chore: update tsconfig to the latest spec * chore: adjust code to typescript 6 * chore: add @types/runes to avoid writing a dts
1 parent 7978cfa commit fa48d89

8 files changed

Lines changed: 66 additions & 53 deletions

File tree

lib/declarations.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module '@drblaster/pipe' {
2+
export function pipe<T>(...fns: Array<(arg: T) => T>): (arg: T) => T;
3+
}

lib/server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import { requestFormatter, dilate, parsePort } from './utils';
66
import config from './config';
77
import { StocazzoRequest, StocazzoResponse } from './types';
88

9-
const sticazzi = config.routes;
9+
const sticazzi: Record<string, { value: string; big: string }> = config.routes;
1010

1111
const server = fastify();
1212

1313
server.register(cors);
1414

15-
server.get('/:format', (request: StocazzoRequest, reply: FastifyReply) => {
16-
const {
17-
params: { format },
18-
} = request;
15+
server.get<StocazzoRequest>(
16+
'/:format',
17+
(request, reply: FastifyReply) => {
18+
const { format } = request.params;
1919
const fallback = !(format && sticazzi[format]);
2020
const obj = fallback ? sticazzi.root : sticazzi[format];
2121
const response = { response: obj.value };

lib/types.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
import { FastifyRequest } from 'fastify';
2-
3-
type StocazzoRequestContent = {
1+
export interface StocazzoRequestContent {
42
params?: {
53
format: string;
64
};
7-
query?: {
5+
query: {
86
big?: number;
97
q: string;
108
};
11-
};
9+
}
1210

13-
export type StocazzoRequest =
14-
| StocazzoRequestContent
15-
| FastifyRequest<{
16-
Params: {
17-
format: string;
18-
};
19-
Querystring: {
20-
big: number;
21-
q: string;
22-
};
23-
}>;
11+
export interface StocazzoRequest {
12+
Params: {
13+
format: string;
14+
};
15+
Querystring: {
16+
big: number;
17+
q: string;
18+
};
19+
}
2420

2521
export interface StocazzoResponse {
2622
response: string;

lib/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { substr } from 'runes';
2-
import { StocazzoRequest, StocazzoResponse } from './types';
2+
import { StocazzoRequestContent, StocazzoResponse } from './types';
33

44
type Port = string | number;
55

66
export const requestFormatter =
7-
(req: StocazzoRequest) =>
7+
(req: StocazzoRequestContent) =>
88
(res: StocazzoResponse): StocazzoResponse => {
99
if (req.query.q) {
1010
res.query = req.query.q;
@@ -16,7 +16,7 @@ export const requestFormatter =
1616
};
1717

1818
export const dilate =
19-
(req: StocazzoRequest) =>
19+
(req: StocazzoRequestContent) =>
2020
(s: string) =>
2121
(res: StocazzoResponse): StocazzoResponse => {
2222
const { response } = res;

package-lock.json

Lines changed: 22 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
3131
},
3232
"devDependencies": {
3333
"@types/jest": "^30.0.0",
34+
"@types/runes": "^0.4.3",
3435
"@typescript-eslint/eslint-plugin": "^8.58.1",
3536
"@typescript-eslint/parser": "^8.58.1",
3637
"eslint": "^10.2.0",
3738
"jest": "^30.3.0",
3839
"prettier": "3.8.2",
3940
"ts-jest": "^29.4.9",
40-
"typescript": "^5.9.3"
41+
"typescript": "^6.0.2"
4142
}
4243
}

test/stocazzo.test.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import { FastifyInstance } from 'fastify';
12
import { init } from '../lib/server';
23

34
describe("Testing stocazzo's", () => {
4-
let server;
5+
let server: FastifyInstance;
56

67
beforeEach(async () => {
78
server = await init();
89
});
910

1011
it('GET /', async () => {
1112
const options = {
12-
method: 'GET',
13+
method: 'GET' as const,
1314
url: '/',
1415
};
1516

@@ -20,7 +21,7 @@ describe("Testing stocazzo's", () => {
2021

2122
it('GET / with request body', async () => {
2223
const options = {
23-
method: 'GET',
24+
method: 'GET' as const,
2425
url: '/?q=chi%20e',
2526
};
2627

@@ -32,7 +33,7 @@ describe("Testing stocazzo's", () => {
3233

3334
it('GET /caps', async () => {
3435
const options = {
35-
method: 'GET',
36+
method: 'GET' as const,
3637
url: '/caps',
3738
};
3839

@@ -43,7 +44,7 @@ describe("Testing stocazzo's", () => {
4344

4445
it('GET /caps with request body', async () => {
4546
const options = {
46-
method: 'GET',
47+
method: 'GET' as const,
4748
url: '/caps?q=chi%20e',
4849
};
4950

@@ -55,7 +56,7 @@ describe("Testing stocazzo's", () => {
5556

5657
it('GET /camel', async () => {
5758
const options = {
58-
method: 'GET',
59+
method: 'GET' as const,
5960
url: '/camel',
6061
};
6162

@@ -66,7 +67,7 @@ describe("Testing stocazzo's", () => {
6667

6768
it('GET /ascii', async () => {
6869
const options = {
69-
method: 'GET',
70+
method: 'GET' as const,
7071
url: '/ascii',
7172
};
7273

@@ -77,7 +78,7 @@ describe("Testing stocazzo's", () => {
7778

7879
it('GET /snake', async () => {
7980
const options = {
80-
method: 'GET',
81+
method: 'GET' as const,
8182
url: '/snake',
8283
};
8384

@@ -88,7 +89,7 @@ describe("Testing stocazzo's", () => {
8889

8990
it('GET /snake with big=true', async () => {
9091
const options = {
91-
method: 'GET',
92+
method: 'GET' as const,
9293
url: '/snake?big=1',
9394
};
9495

@@ -99,7 +100,7 @@ describe("Testing stocazzo's", () => {
99100

100101
it('GET /sto-conte', async () => {
101102
const options = {
102-
method: 'GET',
103+
method: 'GET' as const,
103104
url: '/sto-conte',
104105
};
105106

@@ -110,7 +111,7 @@ describe("Testing stocazzo's", () => {
110111

111112
it('GET /sto-conte with big=true', async () => {
112113
const options = {
113-
method: 'GET',
114+
method: 'GET' as const,
114115
url: '/sto-conte?big=1',
115116
};
116117

@@ -121,7 +122,7 @@ describe("Testing stocazzo's", () => {
121122

122123
it('GET /varg', async () => {
123124
const options = {
124-
method: 'GET',
125+
method: 'GET' as const,
125126
url: '/varg',
126127
};
127128

@@ -132,7 +133,7 @@ describe("Testing stocazzo's", () => {
132133

133134
it('GET /varg with big enabled', async () => {
134135
const options = {
135-
method: 'GET',
136+
method: 'GET' as const,
136137
url: '/varg?big=1',
137138
};
138139

tsconfig.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
{
22
"compilerOptions": {
3-
"baseUrl": ".",
43
"lib": ["es2018", "DOM"],
5-
"paths": {
6-
"*": ["*"]
7-
},
84
"allowJs": true,
9-
"target": "es2016",
10-
"module": "commonjs",
11-
"moduleResolution": "node",
5+
"target": "es2022",
6+
"module": "nodenext",
7+
"moduleResolution": "nodenext",
128
"sourceMap": true,
139
"outDir": "./dist",
14-
"esModuleInterop": true
10+
"esModuleInterop": true,
11+
"types": ["jest", "node", "runes"]
1512
},
1613
"include": ["**/*.ts"],
1714
"exclude": ["node_modules"]

0 commit comments

Comments
 (0)