Improve type safety by using more specific function types

This commit is contained in:
Henry Mercer 2024-06-13 19:26:45 +01:00
parent 2e69043274
commit d8f549d6d8
9 changed files with 21 additions and 14 deletions

View file

@ -1,10 +1,15 @@
import * as core from "@actions/core";
import * as actionsUtil from "./actions-util";
import { getConfig } from "./config-utils";
import { Config, getConfig } from "./config-utils";
import { getActionsLogger } from "./logging";
export async function run(uploadSarifDebugArtifact: Function) {
export async function run(
uploadSarifDebugArtifact: (
config: Config,
outputDir: string,
) => Promise<void>,
) {
const logger = getActionsLogger();
const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger);

View file

@ -233,14 +233,14 @@ export interface BetterResolveLanguagesOutput {
export interface ResolveQueriesOutput {
byLanguage: {
[language: string]: {
[queryPath: string]: {};
[queryPath: string]: object;
};
};
noDeclaredLanguage: {
[queryPath: string]: {};
[queryPath: string]: object;
};
multipleDeclaredLanguages: {
[queryPath: string]: {};
[queryPath: string]: object;
};
}

View file

@ -81,7 +81,7 @@ function createConfigFile(inputFileContents: string, tmpDir: string): string {
return configFilePath;
}
type GetContentsResponse = { content?: string } | Array<{}>;
type GetContentsResponse = { content?: string } | object[];
function mockGetContents(
content: GetContentsResponse,

View file

@ -1065,7 +1065,7 @@ function createRegistriesBlock(registries: RegistryConfigWithCredentials[]): {
*/
export async function wrapEnvironment(
env: Record<string, string | undefined>,
operation: Function,
operation: () => Promise<void>,
) {
// Remember the original env
const oldEnv = { ...process.env };

View file

@ -163,9 +163,12 @@ export async function tryUploadSarifIfRunFailed(
}
export async function run(
uploadDatabaseBundleDebugArtifact: Function,
uploadLogsDebugArtifact: Function,
printDebugLogs: Function,
uploadDatabaseBundleDebugArtifact: (
config: Config,
logger: Logger,
) => Promise<void>,
uploadLogsDebugArtifact: (config: Config) => Promise<void>,
printDebugLogs: (config: Config) => Promise<void>,
config: Config,
repositoryNwo: RepositoryNwo,
features: FeatureEnablement,