Legacy systems are business-critical software products that are difficult to understand and modify. Many are written in dynamically typed languages like JavaScript or Python, which lack the benefits of static type annotations for documentation, error prevention, and maintainability. Manually retrofitting types to large legacy codebases requires significant effort, often taking years. Existing automated approaches have limited practical applicability: static type inference cannot handle dynamic language features, dynamic inference requires comprehensive test suites, and probabilistic inference is inherently unsound. No prior approach achieves both high type coverage and correctness at the repository level. In this thesis, I investigate the use of agentic Artificial Intelligence (AI) —systems composed of Large Language Model (LLM) -based agents—to enable automated typing of legacy software projects. Through a systematic literature review, I identify the challenges and limitations of existing approaches. To overcome these, I propose a three-phase typing approach: (1) type-checking setup with initial error resolution, (2) type annotation and definition generation, and (3) strict type checking with refactoring. I implement the first two phases in AgenticTyper, an open-source tool for JavaScript and TypeScript repositories. My key innovation is a transpilation-based behavior preservation mechanism that prevents unintended modifications and addresses trust issues when using LLMs on production code. I evaluate the approach through a case study on three proprietary legacy repositories with 456, 000 lines of code. Phase one successfully sets up type checking and resolves all 633 initial errors for 25 in LLM API costs, compared to eight hours of manual effort for a single repository. Phase two achieves 86-96% type coverage with zero remaining type errors, costing 4 to 95 and requiring 4-70 hours of human review time depending on repository size. AgenticTyper surfaces 135 manually confirmed bugs and 40 possible bugs through increased type coverage that were previously unknown to the developers. A comparison with prior work shows that most existing tools are inapplicable or achieve at most 81. 5% coverage while introducing thousands of type errors. Furthermore, a non-agentic LLM baseline fails to preserve runtime behavior. The results validate that agentic AI enables automated typing at a practical level that prior approaches could not achieve, substantially reduces manual effort compared to fully manual typing, and identifies numerous existing issues. However, full automation is not achieved: human review remains essential for high-quality results, as manual cleanup reduces the number of added lines by 15-41% without sacrificing type coverage. Ultimately, the resulting pull requests, comprising 35, 000 inserted lines, were merged by the development team, demonstrating the approach's practical value.
Clemens Pohle (Thu,) studied this question.