Skip to content

Commit fb970a5

Browse files
committed
Add type hints
1 parent 778efb1 commit fb970a5

26 files changed

+284
-1194
lines changed

.eslintrc.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

.prettierrc.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Gabriel Massadas
3+
Copyright (c) 2024 Gabriel Massadas
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,28 @@ export default {
4747
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
4848
const qb = new D1QB(env.DB)
4949

50-
const fetched = await qb
51-
.fetchOne({
50+
type Employee = {
51+
name: string
52+
role: string
53+
level: number
54+
}
55+
56+
const employeeList = await qb
57+
.fetchOne<Employee>({
5258
tableName: 'employees',
53-
fields: 'count(*) as count',
59+
fields: '*',
5460
where: {
5561
conditions: 'active = ?1',
5662
params: [true],
5763
},
5864
})
5965
.execute()
6066

67+
// You get IDE type hints on each employee data, like:
68+
// employeeList.results[0].name
69+
6170
return Response.json({
62-
activeEmployees: fetched.results?.count || 0,
71+
activeEmployees: employeeList.results?.length || 0,
6372
})
6473
},
6574
}

jest.config.js renamed to jest.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
transform: {
55
'^.+\\.(ts|tsx)$': 'ts-jest',
66
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
7-
'./config/fileTransformer.js',
7+
'./config/fileTransformer.cjs',
88
},
99
globals: {
1010
'ts-jest': {

0 commit comments

Comments
 (0)