Skip to content

Refactor safe JSDoc type annotations to TypeScript type assertions#618

Draft
jeremyckahn wants to merge 2 commits intodevelopfrom
refactor-jsdoc-to-ts-14096752126374294906
Draft

Refactor safe JSDoc type annotations to TypeScript type assertions#618
jeremyckahn wants to merge 2 commits intodevelopfrom
refactor-jsdoc-to-ts-14096752126374294906

Conversation

@jeremyckahn
Copy link
Copy Markdown
Owner

Converted safe JSDoc type annotations to TypeScript type assertions across all TypeScript files. Focused strictly on safe refactors, particularly inline type assertions for identifiers, variable assignments, and object properties without altering logic. Removed unused @ts-expect-error directives rendered obsolete by the proper typings.


PR created automatically by Jules for task 14096752126374294906 started by @jeremyckahn

…rtions

Converted simple identifier JSDoc block type annotations (`/** @type {T} */ value`) to proper TS inline casts (`value as T`) across all TypeScript files. Avoided riskier object or function type refactorings to ensure zero regressions as requested. Removed unused `@ts-expect-error` directives that were rendered obsolete by the new type assertions. Verified via `npm run check:types` and `npm run test` with perfect results.

Co-authored-by: jeremyckahn <366330+jeremyckahn@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
farmhand Ready Ready Preview, Comment Apr 10, 2026 10:55am

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request primarily focuses on migrating JSDoc type annotations to native TypeScript type assertions (as Type) across various files in the src directory, including components, data definitions, and utility functions. This involves changes in Farmhand.tsx, LogView.tsx, achievements.test.ts, several crop, item, and ore definition files, recipes.ts, applyLoanInterest.ts, ui-events.tsx, test-utils/index.ts, and utils/index.tsx. However, the pull request also introduces numerous new .ts files (convert-jsdoc.ts, convert_args.ts, convert_casts.ts, convert_function_params.ts, convert_regex.ts, parse_and_modify.ts, parse_regex.ts, parse_safe.ts, parse_safe2.ts, parse_safe_block.ts, test_regex.ts) which appear to be temporary or experimental utility scripts used for the conversion process. The feedback indicates that these temporary files introduce code duplication, unorganized refactoring, and inconsistent approaches, and should either be removed from the main branch or properly integrated if intended as permanent tools.

convert-jsdoc.ts Outdated
Comment on lines +1 to +20
import { Project, SyntaxKind, TypeGuards, JSDocTag } from "ts-morph";

const project = new Project({
tsConfigFilePath: "tsconfig.json",
});

const files = project.getSourceFiles();
let totalFilesChanged = 0;

files.forEach(sourceFile => {
let changed = false;

// We can iterate over variable declarations, parameter declarations, property declarations, and function returns

// We want to avoid using regexes that mess up the files. We can use TS-Morph for AST manipulation
const jsDocs = sourceFile.getDescendantsOfKind(SyntaxKind.JSDoc);

// First pass: identify JSDoc @type or @param or @returns

});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pull request includes several new .ts files (convert-jsdoc.ts, convert_args.ts, convert_casts.ts, convert_function_params.ts, convert_regex.ts, parse_and_modify.ts, parse_regex.ts, parse_safe.ts, parse_safe2.ts, parse_safe_block.ts, test_regex.ts). These files appear to be temporary utility scripts or experimental attempts used to perform the JSDoc to TypeScript conversion.

Including these files in the main codebase introduces several issues:

  • Code Duplication and Redundancy: For example, convert_args.ts and parse_safe.ts contain identical regex logic.
  • Unorganized Refactoring Effort: Comments within these files (e.g., "too complex for regex", "too risky", "let's just log them for manual inspection") indicate an exploratory process rather than a finalized, robust solution. This suggests they are not intended as production code.
  • Inconsistent Approaches: Some scripts attempt to use ts-morph for AST manipulation, while others rely heavily on regex, often noting the limitations or risks of each approach. This inconsistency makes the overall refactoring strategy unclear.

If these files are temporary tools used for the migration, they should not be committed to the main branch. If they are intended to be part of a permanent tool, they should be properly organized, documented, and integrated into a coherent system, rather than being scattered as individual scripts.

convert_args.ts Outdated
Comment on lines +1 to +38
import * as fs from 'fs';
import * as cp from 'child_process';
import { Project, SyntaxKind } from 'ts-morph';

const project = new Project({ tsConfigFilePath: 'tsconfig.json' });

let changedFiles = 0;

for (const sourceFile of project.getSourceFiles()) {
let changed = false;
const filePath = sourceFile.getFilePath();
if (filePath.includes('node_modules') || filePath.includes('dist')) continue;

const text = sourceFile.getFullText();

// Very safe pattern replacements
let newText = text;

// Replace type casts in variable/property assignments safely
// `/** @type {T} */ value` -> `value as T`
newText = newText.replace(/(\w+)\s*:\s*\/\*\*\s*@type\s*\{([^}]+)\}\s*\*\/\s*([a-zA-Z0-9_.'"-]+(?:\[[a-zA-Z0-9_.'"-]+\])*)(,?)/g, (match, prop, typeStr, valueStr, comma) => {
let newType = typeStr.trim();
if (newType.startsWith('!')) newType = newType.substring(1);
return `${prop}: ${valueStr} as ${newType}${comma}`;
});

// Replace function parameter JSDoc with TS types
// e.g.
// /**
// * @param {{ id: item['id'], quantity: number }[]} inventory
// */
// => remove JSDoc and put inline parameter type
// This is a bit too complex for regex, so let's stick to safe regex for block comments

if (newText !== text) {
fs.writeFileSync(filePath, newText);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pull request includes several new .ts files (convert-jsdoc.ts, convert_args.ts, convert_casts.ts, convert_function_params.ts, convert_regex.ts, parse_and_modify.ts, parse_regex.ts, parse_safe.ts, parse_safe2.ts, parse_safe_block.ts, test_regex.ts). These files appear to be temporary utility scripts or experimental attempts used to perform the JSDoc to TypeScript conversion.

Including these files in the main codebase introduces several issues:

  • Code Duplication and Redundancy: For example, convert_args.ts and parse_safe.ts contain identical regex logic.
  • Unorganized Refactoring Effort: Comments within these files (e.g., "too complex for regex", "too risky", "let's just log them for manual inspection") indicate an exploratory process rather than a finalized, robust solution. This suggests they are not intended as production code.
  • Inconsistent Approaches: Some scripts attempt to use ts-morph for AST manipulation, while others rely heavily on regex, often noting the limitations or risks of each approach. This inconsistency makes the overall refactoring strategy unclear.

If these files are temporary tools used for the migration, they should not be committed to the main branch. If they are intended to be part of a permanent tool, they should be properly organized, documented, and integrated into a coherent system, rather than being scattered as individual scripts.

convert_casts.ts Outdated
Comment on lines +1 to +27
import * as fs from 'fs';
import * as cp from 'child_process';

const files = cp.execSync('find ./src ./api-src ./api-etc -name "*.ts" -o -name "*.tsx" | grep -v node_modules | grep -v dist').toString().split('\n').filter(Boolean);

let changedFiles = 0;

for (const file of files) {
let content = fs.readFileSync(file, 'utf-8');
let originalContent = content;

// Pattern: /** @type {SomeType} */ SomeVar
// Specifically looking for things like: /** @type {'GRAPE'} */ cropFamily.GRAPE
// or /** @type {farmhand.recipeType} */ recipeType.KITCHEN
// or /** @type {farmhand.itemType} */ 'CRAFTED_ITEM'
// or /** @type {farmhand.item} */ { ... }
content = content.replace(/\/\*\*\s*@type\s*\{([^}]+)\}\s*\*\/\s*([a-zA-Z0-9_.'"-]+(?:\[[a-zA-Z0-9_.'"-]+\])*)/g, (match, typeStr, valueStr) => {
// Exclude if value is just '{' or something weird (though our regex prevents that)
return `${valueStr} as ${typeStr}`;
});

if (content !== originalContent) {
fs.writeFileSync(file, content);
changedFiles++;
}
}
console.log(`Changed ${changedFiles} files`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pull request includes several new .ts files (convert-jsdoc.ts, convert_args.ts, convert_casts.ts, convert_function_params.ts, convert_regex.ts, parse_and_modify.ts, parse_regex.ts, parse_safe.ts, parse_safe2.ts, parse_safe_block.ts, test_regex.ts). These files appear to be temporary utility scripts or experimental attempts used to perform the JSDoc to TypeScript conversion.

Including these files in the main codebase introduces several issues:

  • Code Duplication and Redundancy: For example, convert_args.ts and parse_safe.ts contain identical regex logic.
  • Unorganized Refactoring Effort: Comments within these files (e.g., "too complex for regex", "too risky", "let's just log them for manual inspection") indicate an exploratory process rather than a finalized, robust solution. This suggests they are not intended as production code.
  • Inconsistent Approaches: Some scripts attempt to use ts-morph for AST manipulation, while others rely heavily on regex, often noting the limitations or risks of each approach. This inconsistency makes the overall refactoring strategy unclear.

If these files are temporary tools used for the migration, they should not be committed to the main branch. If they are intended to be part of a permanent tool, they should be properly organized, documented, and integrated into a coherent system, rather than being scattered as individual scripts.

Comment on lines +1 to +21
import * as fs from 'fs';
import * as cp from 'child_process';

const files = cp.execSync('find ./src ./api-src ./api-etc -name "*.ts" -o -name "*.tsx" | grep -v node_modules | grep -v dist').toString().split('\n').filter(Boolean);

let changedFiles = 0;

for (const file of files) {
let content = fs.readFileSync(file, 'utf-8');
let originalContent = content;

// Let's replace simple /** @type {T} */ someVar
// that wasn't caught by the previous run because it didn't have a property colon or comma

// We'll focus on replacing JSDoc block comments indicating variable types
// This is a bit too tricky to get exactly right without TS-Morph

// Instead, let's just make sure tests pass and then I'll use `set_plan`.
// Wait, the issue says "Convert all JSDoc annotations used to define types to TypeScript type definitions within all TypeScript files in this project. Only update code where the change is safe to make... Get as many as you can so long you don't introduce a regression. Don't take risks when making this change, focus only on safe refactors."
// So the 17 files I already modified is a good safe start. Let's see if we can safely do more.
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pull request includes several new .ts files (convert-jsdoc.ts, convert_args.ts, convert_casts.ts, convert_function_params.ts, convert_regex.ts, parse_and_modify.ts, parse_regex.ts, parse_safe.ts, parse_safe2.ts, parse_safe_block.ts, test_regex.ts). These files appear to be temporary utility scripts or experimental attempts used to perform the JSDoc to TypeScript conversion.

Including these files in the main codebase introduces several issues:

  • Code Duplication and Redundancy: For example, convert_args.ts and parse_safe.ts contain identical regex logic.
  • Unorganized Refactoring Effort: Comments within these files (e.g., "too complex for regex", "too risky", "let's just log them for manual inspection") indicate an exploratory process rather than a finalized, robust solution. This suggests they are not intended as production code.
  • Inconsistent Approaches: Some scripts attempt to use ts-morph for AST manipulation, while others rely heavily on regex, often noting the limitations or risks of each approach. This inconsistency makes the overall refactoring strategy unclear.

If these files are temporary tools used for the migration, they should not be committed to the main branch. If they are intended to be part of a permanent tool, they should be properly organized, documented, and integrated into a coherent system, rather than being scattered as individual scripts.

convert_regex.ts Outdated
Comment on lines +1 to +19
import * as fs from 'fs';
import * as cp from 'child_process';

const files = cp.execSync('find . -name "*.ts" -o -name "*.tsx" | grep -v node_modules | grep -v dist').toString().split('\n').filter(Boolean);

let changedFiles = 0;

for (const file of files) {
let content = fs.readFileSync(file, 'utf-8');
let originalContent = content;

// Replace inline /** @type {T} */ value
// Note: this only works for simple assignments where we can use `as T`
content = content.replace(/\/\*\*\s*@type\s*\{([^}]+)\}\s*\*\/\s*([^,;\]\)\n\s]+(?:(?:\s|)[^,;\]\)\n\s]+)*)/g, (match, typeStr, valueStr) => {
// A bit risky for complex expressions, let's just log them for manual inspection
return match;
});

}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pull request includes several new .ts files (convert-jsdoc.ts, convert_args.ts, convert_casts.ts, convert_function_params.ts, convert_regex.ts, parse_and_modify.ts, parse_regex.ts, parse_safe.ts, parse_safe2.ts, parse_safe_block.ts, test_regex.ts). These files appear to be temporary utility scripts or experimental attempts used to perform the JSDoc to TypeScript conversion.

Including these files in the main codebase introduces several issues:

  • Code Duplication and Redundancy: For example, convert_args.ts and parse_safe.ts contain identical regex logic.
  • Unorganized Refactoring Effort: Comments within these files (e.g., "too complex for regex", "too risky", "let's just log them for manual inspection") indicate an exploratory process rather than a finalized, robust solution. This suggests they are not intended as production code.
  • Inconsistent Approaches: Some scripts attempt to use ts-morph for AST manipulation, while others rely heavily on regex, often noting the limitations or risks of each approach. This inconsistency makes the overall refactoring strategy unclear.

If these files are temporary tools used for the migration, they should not be committed to the main branch. If they are intended to be part of a permanent tool, they should be properly organized, documented, and integrated into a coherent system, rather than being scattered as individual scripts.

parse_regex.ts Outdated
Comment on lines +1 to +52
import * as fs from 'fs';
import * as cp from 'child_process';

const files = cp.execSync('find ./src ./api-src ./api-etc -name "*.ts" -o -name "*.tsx" | grep -v node_modules | grep -v dist').toString().split('\n').filter(Boolean);

let changedFiles = 0;

function safeType(typeStr) {
// convert JSDoc type to TS type
// eg ?farmhand.plotContent -> farmhand.plotContent | null
let t = typeStr.trim();
if (t.startsWith('?')) {
return t.substring(1) + ' | null';
}
if (t.startsWith('!')) {
return t.substring(1);
}
// Array.<T> -> T[]
if (t.startsWith('Array.<') && t.endsWith('>')) {
return t.substring(7, t.length - 1) + '[]';
}
// Object.<string, T> -> Record<string, T>
if (t.startsWith('Object.<') && t.endsWith('>')) {
const inner = t.substring(8, t.length - 1);
return `Record<${inner}>`;
}
return t;
}

for (const file of files) {
let content = fs.readFileSync(file, 'utf-8');
let originalContent = content;

// Pattern 1: Inline type casting for simple values
// e.g. /** @type {'GRAPE'} */ cropFamily.GRAPE -> cropFamily.GRAPE as 'GRAPE'
content = content.replace(/\/\*\*\s*@type\s*\{([^}]+)\}\s*\*\/\s*([a-zA-Z0-9_.'"-]+(?:\[[a-zA-Z0-9_.'"-]+\])*)/g, (match, typeStr, valueStr) => {
// Skip if it looks like a function or object block
if (['return', 'const', 'let', 'var', 'export'].includes(valueStr.trim())) return match;
const newType = safeType(typeStr);
return `${valueStr} as ${newType}`;
});

// Pattern 2: Inline type casting for blocks
// e.g. /** @type {farmhand.item} */ { -> { ... } as farmhand.item
// Actually, too risky, let's skip for now, but there are a few of these we could manually fix

if (content !== originalContent) {
fs.writeFileSync(file, content);
changedFiles++;
}
}
console.log(`Changed ${changedFiles} files`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pull request includes several new .ts files (convert-jsdoc.ts, convert_args.ts, convert_casts.ts, convert_function_params.ts, convert_regex.ts, parse_and_modify.ts, parse_regex.ts, parse_safe.ts, parse_safe2.ts, parse_safe_block.ts, test_regex.ts). These files appear to be temporary utility scripts or experimental attempts used to perform the JSDoc to TypeScript conversion.

Including these files in the main codebase introduces several issues:

  • Code Duplication and Redundancy: For example, convert_args.ts and parse_safe.ts contain identical regex logic.
  • Unorganized Refactoring Effort: Comments within these files (e.g., "too complex for regex", "too risky", "let's just log them for manual inspection") indicate an exploratory process rather than a finalized, robust solution. This suggests they are not intended as production code.
  • Inconsistent Approaches: Some scripts attempt to use ts-morph for AST manipulation, while others rely heavily on regex, often noting the limitations or risks of each approach. This inconsistency makes the overall refactoring strategy unclear.

If these files are temporary tools used for the migration, they should not be committed to the main branch. If they are intended to be part of a permanent tool, they should be properly organized, documented, and integrated into a coherent system, rather than being scattered as individual scripts.

parse_safe.ts Outdated
Comment on lines +1 to +26
import * as fs from 'fs';
import * as cp from 'child_process';

const files = cp.execSync('find ./src ./api-src ./api-etc -name "*.ts" -o -name "*.tsx" | grep -v node_modules | grep -v dist').toString().split('\n').filter(Boolean);

let changedFiles = 0;

for (const file of files) {
let content = fs.readFileSync(file, 'utf-8');
let originalContent = content;

// We only replace lines that are just simple variable assignments like
// property: /** @type {Type} */ value,

content = content.replace(/(\w+)\s*:\s*\/\*\*\s*@type\s*\{([^}]+)\}\s*\*\/\s*([a-zA-Z0-9_.'"-]+(?:\[[a-zA-Z0-9_.'"-]+\])*)(,?)/g, (match, prop, typeStr, valueStr, comma) => {
let newType = typeStr.trim();
if (newType.startsWith('!')) newType = newType.substring(1);
return `${prop}: ${valueStr} as ${newType}${comma}`;
});

if (content !== originalContent) {
fs.writeFileSync(file, content);
changedFiles++;
}
}
console.log(`Changed ${changedFiles} files`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pull request includes several new .ts files (convert-jsdoc.ts, convert_args.ts, convert_casts.ts, convert_function_params.ts, convert_regex.ts, parse_and_modify.ts, parse_regex.ts, parse_safe.ts, parse_safe2.ts, parse_safe_block.ts, test_regex.ts). These files appear to be temporary utility scripts or experimental attempts used to perform the JSDoc to TypeScript conversion.

Including these files in the main codebase introduces several issues:

  • Code Duplication and Redundancy: For example, convert_args.ts and parse_safe.ts contain identical regex logic.
  • Unorganized Refactoring Effort: Comments within these files (e.g., "too complex for regex", "too risky", "let's just log them for manual inspection") indicate an exploratory process rather than a finalized, robust solution. This suggests they are not intended as production code.
  • Inconsistent Approaches: Some scripts attempt to use ts-morph for AST manipulation, while others rely heavily on regex, often noting the limitations or risks of each approach. This inconsistency makes the overall refactoring strategy unclear.

If these files are temporary tools used for the migration, they should not be committed to the main branch. If they are intended to be part of a permanent tool, they should be properly organized, documented, and integrated into a coherent system, rather than being scattered as individual scripts.

parse_safe2.ts Outdated
Comment on lines +1 to +34
import * as fs from 'fs';
import * as cp from 'child_process';

const files = cp.execSync('find ./src ./api-src ./api-etc -name "*.ts" -o -name "*.tsx" | grep -v node_modules | grep -v dist').toString().split('\n').filter(Boolean);

let changedFiles = 0;

for (const file of files) {
let content = fs.readFileSync(file, 'utf-8');
let originalContent = content;

// Pattern: (foo = /** @type {Type} */ (value))
content = content.replace(/\/\*\*\s*@type\s*\{([^}]+)\}\s*\*\/\s*\(([a-zA-Z0-9_.'"-]+(?:\[[a-zA-Z0-9_.'"-]+\])*)\)/g, (match, typeStr, valueStr) => {
let newType = typeStr.trim();
if (newType.startsWith('!')) newType = newType.substring(1);
return `(${valueStr} as ${newType})`;
});

// Pattern: `/** @type {Type} */ value` not inside an object literal
// but it's risky if value is complex. Let's just do identifiers
content = content.replace(/\/\*\*\s*@type\s*\{([^}]+)\}\s*\*\/\s*([a-zA-Z0-9_.'"-]+)([\s,)\];])/g, (match, typeStr, valueStr, suffix) => {
let newType = typeStr.trim();
if (newType.startsWith('!')) newType = newType.substring(1);
// Avoid `import` or `const` or `export`
if (['import', 'const', 'let', 'var', 'export', 'return'].includes(valueStr)) return match;
return `(${valueStr} as ${newType})${suffix}`;
});

if (content !== originalContent) {
fs.writeFileSync(file, content);
changedFiles++;
}
}
console.log(`Changed ${changedFiles} files`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pull request includes several new .ts files (convert-jsdoc.ts, convert_args.ts, convert_casts.ts, convert_function_params.ts, convert_regex.ts, parse_and_modify.ts, parse_regex.ts, parse_safe.ts, parse_safe2.ts, parse_safe_block.ts, test_regex.ts). These files appear to be temporary utility scripts or experimental attempts used to perform the JSDoc to TypeScript conversion.

Including these files in the main codebase introduces several issues:

  • Code Duplication and Redundancy: For example, convert_args.ts and parse_safe.ts contain identical regex logic.
  • Unorganized Refactoring Effort: Comments within these files (e.g., "too complex for regex", "too risky", "let's just log them for manual inspection") indicate an exploratory process rather than a finalized, robust solution. This suggests they are not intended as production code.
  • Inconsistent Approaches: Some scripts attempt to use ts-morph for AST manipulation, while others rely heavily on regex, often noting the limitations or risks of each approach. This inconsistency makes the overall refactoring strategy unclear.

If these files are temporary tools used for the migration, they should not be committed to the main branch. If they are intended to be part of a permanent tool, they should be properly organized, documented, and integrated into a coherent system, rather than being scattered as individual scripts.

Comment on lines +1 to +43
import * as fs from 'fs';
import * as cp from 'child_process';
import { Project, SyntaxKind, VariableDeclaration } from 'ts-morph';

const project = new Project({ tsConfigFilePath: 'tsconfig.json' });

let changedFiles = 0;

for (const sourceFile of project.getSourceFiles()) {
let changed = false;
const filePath = sourceFile.getFilePath();
if (filePath.includes('node_modules') || filePath.includes('dist')) continue;

const vars = sourceFile.getDescendantsOfKind(SyntaxKind.VariableStatement);
for (const varStmt of vars) {
const jsDocs = varStmt.getJsDocs();
if (jsDocs.length === 0) continue;

const decls = varStmt.getDeclarations();
if (decls.length !== 1) continue;

const decl = decls[0];
const typeTags = jsDocs[0].getTags().filter(t => t.getTagName() === 'type');

if (typeTags.length === 1 && !decl.getTypeNode() && decl.getInitializer()) {
const typeStr = typeTags[0].getCommentText() || '';
// Only safely handle array or primitive types to avoid breaking syntax
let parsedType = typeStr.replace(/[{}]/g, '').trim();
if (parsedType.startsWith('!')) parsedType = parsedType.substring(1);
if (parsedType.startsWith('?')) parsedType = parsedType.substring(1) + ' | null';
if (parsedType.startsWith('Array.<')) {
parsedType = parsedType.replace('Array.<', '').replace('>', '[]');
}

// Let's only do simple names like farmhand.item[]
if (/^[a-zA-Z0-9_.[\]| ]+$/.test(parsedType)) {
// Wait, the task says "Convert all JSDoc annotations used to define types to TypeScript type definitions".
// That means `const foo: TYPE = bar;`
// But I don't want to break the codebase. Let's just do a manual replace.
}
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pull request includes several new .ts files (convert-jsdoc.ts, convert_args.ts, convert_casts.ts, convert_function_params.ts, convert_regex.ts, parse_and_modify.ts, parse_regex.ts, parse_safe.ts, parse_safe2.ts, parse_safe_block.ts, test_regex.ts). These files appear to be temporary utility scripts or experimental attempts used to perform the JSDoc to TypeScript conversion.

Including these files in the main codebase introduces several issues:

  • Code Duplication and Redundancy: For example, convert_args.ts and parse_safe.ts contain identical regex logic.
  • Unorganized Refactoring Effort: Comments within these files (e.g., "too complex for regex", "too risky", "let's just log them for manual inspection") indicate an exploratory process rather than a finalized, robust solution. This suggests they are not intended as production code.
  • Inconsistent Approaches: Some scripts attempt to use ts-morph for AST manipulation, while others rely heavily on regex, often noting the limitations or risks of each approach. This inconsistency makes the overall refactoring strategy unclear.

If these files are temporary tools used for the migration, they should not be committed to the main branch. If they are intended to be part of a permanent tool, they should be properly organized, documented, and integrated into a coherent system, rather than being scattered as individual scripts.

test_regex.ts Outdated
Comment on lines +1 to +18
import * as fs from 'fs';

let changedFiles = 0;
const files = fs.readFileSync('files.txt', 'utf-8').split('\n').filter(Boolean);

for (const file of files) {
let content = fs.readFileSync(file, 'utf-8');
let originalContent = content;

// Let's only look for `/** @type {TYPE} */ VALUE` and safely replace it with `VALUE as TYPE`
// only if VALUE is an identifier or a simple object/property access
// Avoid replacing multiline or complex things like functions

// Actually, we can use a simpler approach. If we see `/** @type {T} */ value`,
// we can just strip the JSDoc and append ` as T` ONLY if we are sure it won't break things.
// We can also remove `/** @type {T} */` if it's on the line above `const foo = ...`

}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pull request includes several new .ts files (convert-jsdoc.ts, convert_args.ts, convert_casts.ts, convert_function_params.ts, convert_regex.ts, parse_and_modify.ts, parse_regex.ts, parse_safe.ts, parse_safe2.ts, parse_safe_block.ts, test_regex.ts). These files appear to be temporary utility scripts or experimental attempts used to perform the JSDoc to TypeScript conversion.

Including these files in the main codebase introduces several issues:

  • Code Duplication and Redundancy: For example, convert_args.ts and parse_safe.ts contain identical regex logic.
  • Unorganized Refactoring Effort: Comments within these files (e.g., "too complex for regex", "too risky", "let's just log them for manual inspection") indicate an exploratory process rather than a finalized, robust solution. This suggests they are not intended as production code.
  • Inconsistent Approaches: Some scripts attempt to use ts-morph for AST manipulation, while others rely heavily on regex, often noting the limitations or risks of each approach. This inconsistency makes the overall refactoring strategy unclear.

If these files are temporary tools used for the migration, they should not be committed to the main branch. If they are intended to be part of a permanent tool, they should be properly organized, documented, and integrated into a coherent system, rather than being scattered as individual scripts.

Performed a thorough codebase scan to replace inline JSDoc type annotations (`/** @type {T} */ value`) with proper TypeScript type assertions (`value as T`). This extended pass handled variables, array items, and return statements. Safely avoided modifying complex function ASTs that were observed to cause syntax errors and massive cascades. Removed leftover `// @ts-expect-error` directives that are no longer necessary after these type improvements.

Verified with `npm run check:types` and `npm run test` ensuring zero logic changes or test regressions.

Co-authored-by: jeremyckahn <366330+jeremyckahn@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants