refactor: tighten typescript types (#15965)

This commit is contained in:
Michael Kriese 2022-06-09 14:17:05 +02:00 committed by GitHub
parent 0248f956d5
commit 49d851e5fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 12 deletions

View file

@ -304,8 +304,10 @@ describe('config/migration', () => {
expect(isMigrated).toBeTrue();
expect(migratedConfig).toMatchSnapshot();
expect(migratedConfig.lockFileMaintenance?.packageRules).toHaveLength(1);
// TODO: fix types #7154
expect(
migratedConfig.lockFileMaintenance?.packageRules[0].respectLatest
(migratedConfig.lockFileMaintenance as RenovateConfig)
?.packageRules?.[0].respectLatest
).toBeFalse();
});

View file

@ -221,7 +221,8 @@ export function migrateConfig(config: RenovateConfig): MigratedConfig {
for (const [oldKey, ruleVal] of Object.entries(packageRule)) {
const newKey = renameMap[oldKey as keyof typeof renameMap];
if (newKey) {
packageRule[newKey] = ruleVal;
// TODO: fix types #7154
packageRule[newKey] = ruleVal as never;
delete packageRule[oldKey];
}
}

View file

@ -7,7 +7,7 @@ export class CompatibilityMigration extends AbstractMigration {
override run(value: unknown): void {
if (is.object(value)) {
this.setSafely('constraints', value);
this.setSafely('constraints', value as Record<string, string>);
}
}
}

View file

@ -38,6 +38,7 @@ export interface RenovateSharedConfig {
enabledManagers?: string[];
extends?: string[];
fileMatch?: string[];
force?: RenovateConfig;
group?: GroupConfig;
groupName?: string;
groupSlug?: string;
@ -58,6 +59,7 @@ export interface RenovateSharedConfig {
productLinks?: Record<string, string>;
prPriority?: number;
rebaseLabel?: string;
respectLatest?: boolean;
stopUpdatingLabel?: string;
rebaseWhen?: string;
recreateClosed?: boolean;
@ -140,16 +142,18 @@ export interface LegacyAdminConfig {
requireConfig?: RequiredConfig;
}
export type ExecutionMode = 'branch' | 'update';
export type PostUpgradeTasks = {
export interface PostUpgradeTasks {
commands?: string[];
fileFilters?: string[];
executionMode: ExecutionMode;
};
}
type UpdateConfig<T extends RenovateSharedConfig = RenovateSharedConfig> =
Partial<Record<UpdateType, T | null>>;
export type UpdateConfig<
T extends RenovateSharedConfig = RenovateSharedConfig
> = Partial<Record<UpdateType, T | null>>;
export type RenovateRepository =
| string
@ -228,6 +232,8 @@ export interface RenovateConfig
fetchReleaseNotes?: boolean;
secrets?: Record<string, string>;
constraints?: Record<string, string>;
}
export interface AllConfig extends RenovateConfig, GlobalOnlyConfig {}
@ -269,7 +275,8 @@ export type MergeStrategy =
export interface PackageRule
extends RenovateSharedConfig,
UpdateConfig,
Record<string, any> {
Record<string, unknown> {
description?: string | string[];
matchFiles?: string[];
matchPaths?: string[];
matchLanguages?: string[];
@ -287,6 +294,7 @@ export interface PackageRule
matchSourceUrlPrefixes?: string[];
matchSourceUrls?: string[];
matchUpdateTypes?: UpdateType[];
registryUrls?: string[];
}
export interface ValidationMessage {

View file

@ -488,7 +488,7 @@ describe('config/validation', () => {
constraints: { packageRules: [{}] },
};
const { warnings, errors } = await configValidation.validateConfig(
config,
config as never, // TODO: #15963
true
);
expect(warnings).toHaveLength(0);

View file

@ -173,7 +173,9 @@ export function resolveRegistryUrl(packageName: string): string {
!matchPackagePrefixes ||
packageName.startsWith(matchPackagePrefixes[0])
) {
registryUrl = registryUrls[0];
// TODO: fix types #7154
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
registryUrl = registryUrls![0];
}
}
return registryUrl;

View file

@ -40,7 +40,6 @@ export interface BranchUpgradeConfig
excludeCommitPaths?: string[];
githubName?: string;
group?: GroupConfig;
constraints?: Record<string, string>;
groupName?: string;
groupSlug?: string;
language?: string;

View file

@ -38,7 +38,7 @@ export async function generatePresets(dist: string): Promise<void> {
delete value.description;
if (!presetDescription) {
if (value.packageRules?.[0].description) {
presetDescription = value.packageRules[0].description;
presetDescription = value.packageRules[0].description as string;
delete value.packageRules[0].description;
}
}