refactor: add TypeScript type annotations to fix implicit 'any' errors

Fixed 12 type errors by adding proper type annotations:

Quick Wins Completed:
- do_on_key.js: Added JSDoc types for KeyboardEvent and function parameters
- randomize.js: Added JSDoc types with generic template for array shuffling
- cookie.js: Added JSDoc types for Request API
- stripHtmlTags.ts: Added TypeScript types for string parameter

Progress: 12/1239 errors fixed (Quick Wins - Category 1 partial)

Created TODO_cleanup.md to track remaining 1227 type errors systematically.
This commit is contained in:
2026-01-05 23:48:57 +01:00
parent f66334290a
commit 2feb8355b8
5 changed files with 160 additions and 1 deletions

View File

@@ -1,3 +1,9 @@
/**
* @param {KeyboardEvent} event
* @param {string} key
* @param {boolean} needsctrl
* @param {() => void} fn
*/
export function do_on_key(event, key, needsctrl, fn){
if(event.key == key){
if(needsctrl && !event.ctrlKey){

View File

@@ -1,4 +1,8 @@
const MS_PER_DAY = 86400000
/**
* @param {number} a
*/
function mulberry32(a) {
return function() {
var t = a += 0x6D2B79F5;
@@ -8,6 +12,11 @@ function mulberry32(a) {
}
}
/**
* @template T
* @param {T[]} array
* @returns {T[]}
*/
export function rand_array(array){
let time = new Date()
const seed = Math.floor(time.getTime()/MS_PER_DAY)

View File

@@ -1,7 +1,7 @@
// Function to strip HTML tags from a string
import {load} from 'cheerio';
export function stripHtmlTags(input) {
export function stripHtmlTags(input: string): string {
const $ = load(input.replace(/­/g, ''));
return $.text();
}

View File

@@ -1,6 +1,12 @@
// utils/cookie.js
/**
* @param {Request} request
* @returns {string}
*/
export function getJWTFromRequest(request) {
const cookies = request.headers.get("cookie") || '';
/** @param {string} cookie */
const jwtCookie = cookies.split(';').find(cookie => cookie.trim().startsWith('UserSession='));
if (jwtCookie) {