Replace any types with more specific types in the app module

This commit improves type safety across the app module by:
1. Using Partial<CompilerInfo> instead of any[] in compiler-discovery.ts
2. Using express.Handler in controllers.ts for form data handler
3. Using specific interface types instead of any for ClientOptionsHandler and Sponsors
4. Removing unnecessary optional chaining operators
5. Updating test files to be compatible with the improved types

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Matt Godbolt
2025-05-19 10:39:49 -05:00
co-authored by Claude
parent 3423a2375d
commit eae05c403f
7 changed files with 25 additions and 13 deletions
+5 -2
View File
@@ -112,7 +112,7 @@ export async function findAndValidateCompilers(
*/
export async function handleDiscoveryOnlyMode(
savePath: string,
initialCompilers: any[],
initialCompilers: Partial<CompilerInfo>[],
compilerFinder: CompilerFinder,
) {
for (const compiler of initialCompilers) {
@@ -120,7 +120,10 @@ export async function handleDiscoveryOnlyMode(
if (compiler.externalparser && compiler.externalparser.id === '') delete compiler.externalparser;
const compilerInstance = compilerFinder.compileHandler.findCompiler(compiler.lang, compiler.id);
const compilerInstance =
compiler.lang && compiler.id
? compilerFinder.compileHandler.findCompiler(compiler.lang, compiler.id)
: undefined;
if (compilerInstance) {
compiler.cachedPossibleArguments = compilerInstance.possibleArguments.possibleArguments;
}
+2 -1
View File
@@ -22,6 +22,7 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import express from 'express';
import {CompilationQueue} from '../compilation-queue.js';
import {FormattingService} from '../formatting-service.js';
import {AssemblyDocumentationController} from '../handlers/api/assembly-documentation-controller.js';
@@ -57,7 +58,7 @@ export function setupControllersAndHandlers(
compilationQueue: CompilationQueue,
healthCheckFilePath: string | null,
isExecutionWorker: boolean,
formDataHandler: any,
formDataHandler: express.Handler,
): ApiControllers {
// Initialize API controllers
const siteTemplateController = new SiteTemplateController();
+1 -1
View File
@@ -153,7 +153,7 @@ export function setupBasicRoutes(
ceProps: PropertyGetter,
faviconFilename: string,
options: ServerOptions,
clientOptionsHandler: any,
clientOptionsHandler: {getJSON(): string},
): void {
const legacyGoogleUrlHandler = new LegacyGoogleUrlHandler(ceProps);
+3 -2
View File
@@ -26,6 +26,7 @@ import type {Express, Request, Response, Router} from 'express';
import type {GoldenLayoutRootStruct} from '../clientstate-normalizer.js';
import type {ShortLinkMetaData} from '../handlers/handler.interfaces.js';
import type {PropertyGetter} from '../properties.interfaces.js';
import type {Sponsors} from '../sponsors.interfaces.js';
export interface ServerOptions {
staticPath: string;
@@ -79,7 +80,7 @@ export interface WebServerResult {
export interface ServerDependencies {
ceProps: PropertyGetter;
sponsorConfig: any;
clientOptionsHandler: any;
sponsorConfig: Sponsors;
clientOptionsHandler: {get(): Record<string, any>; getHash(): string; getJSON(): string};
storageSolution: string;
}
+5 -4
View File
@@ -35,6 +35,7 @@ import {
} from '../../lib/app/compiler-discovery.js';
import {CompilerFinder} from '../../lib/compiler-finder.js';
import {logger} from '../../lib/logger.js';
import {LanguageKey} from '../../types/languages.interfaces.js';
vi.mock('node:fs/promises');
vi.mock('../../lib/logger.js');
@@ -160,14 +161,14 @@ describe('compiler-discovery module', () => {
const compilers = [
{
id: 'gcc1',
lang: 'c++',
buildenvsetup: {id: ''},
lang: 'c++' as unknown as LanguageKey,
buildenvsetup: {id: '', props: vi.fn()},
externalparser: {id: ''},
},
{
id: 'gcc2',
lang: 'c++',
buildenvsetup: {id: 'setup1'},
lang: 'c++' as unknown as LanguageKey,
buildenvsetup: {id: 'setup1', props: vi.fn()},
externalparser: {id: 'parser1'},
},
];
+4 -2
View File
@@ -91,11 +91,13 @@ describe('Rendering Module', () => {
defaultLanguage: 'c++',
}),
getHash: vi.fn().mockReturnValue('hash123'),
getJSON: vi.fn().mockReturnValue('{}'),
},
storageSolution: 'localStorage',
sponsorConfig: {
showSponsors: true,
displayCount: 6,
getLevels: vi.fn().mockReturnValue([]),
pickTopIcons: vi.fn().mockReturnValue([]),
getAllTopIcons: vi.fn().mockReturnValue([]),
},
ceProps: vi.fn(),
};
+5 -1
View File
@@ -113,7 +113,11 @@ describe('Server Module', () => {
if (key === 'allowedShortUrlHostRe') return '.*';
return '';
}),
sponsorConfig: {},
sponsorConfig: {
getLevels: vi.fn().mockReturnValue([]),
pickTopIcons: vi.fn().mockReturnValue([]),
getAllTopIcons: vi.fn().mockReturnValue([]),
},
clientOptionsHandler: mockClientOptionsHandler,
storageSolution: 'mock-storage',
};