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(isMigrated).toBeTrue();
expect(migratedConfig).toMatchSnapshot(); expect(migratedConfig).toMatchSnapshot();
expect(migratedConfig.lockFileMaintenance?.packageRules).toHaveLength(1); expect(migratedConfig.lockFileMaintenance?.packageRules).toHaveLength(1);
// TODO: fix types #7154
expect( expect(
migratedConfig.lockFileMaintenance?.packageRules[0].respectLatest (migratedConfig.lockFileMaintenance as RenovateConfig)
?.packageRules?.[0].respectLatest
).toBeFalse(); ).toBeFalse();
}); });

View file

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

View file

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

View file

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

View file

@ -173,7 +173,9 @@ export function resolveRegistryUrl(packageName: string): string {
!matchPackagePrefixes || !matchPackagePrefixes ||
packageName.startsWith(matchPackagePrefixes[0]) 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; return registryUrl;

View file

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

View file

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