Skip to content

Commit

Permalink
fix: make typings more accurate by avoiding explict cast on consts
Browse files Browse the repository at this point in the history
  • Loading branch information
fpaul-1A authored and kpanot committed Dec 2, 2024
1 parent faede75 commit 1603bff
Show file tree
Hide file tree
Showing 95 changed files with 219 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export enum PaletteVariant {
*/
export const DEFAULT_PALETTE_VARIANT: PaletteVariant = PaletteVariant.V500;

const SATURATION_VALUES: Record<PaletteVariant, number> = {
const SATURATION_VALUES = {
50: 0.91,
100: 0.98,
200: 0.96,
Expand All @@ -41,9 +41,9 @@ const SATURATION_VALUES: Record<PaletteVariant, number> = {
A200: 1,
A400: 1,
A700: 1
};
} as const satisfies Record<PaletteVariant, number>;

const LIGHTNESS_VALUES: Record<PaletteVariant, number> = {
const LIGHTNESS_VALUES = {
50: 0.12,
100: 0.3,
200: 0.5,
Expand All @@ -58,7 +58,7 @@ const LIGHTNESS_VALUES: Record<PaletteVariant, number> = {
A200: 0.64,
A400: 0.49,
A700: 0.44
};
} as const satisfies Record<PaletteVariant, number>;

/**
* Returns palette colors from one color
Expand Down
4 changes: 2 additions & 2 deletions apps/chrome-devtools/src/services/state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ export class StateService {
...(override ? undefined : state.stylingVariables),
...changes.stylingVariables
}).filter((entry): entry is [string, string] => entry[1] !== null));
const stateOverrides: StateOverride = {
const stateOverrides = {
configurations: Object.keys(configurationOverrides).length > 0 ? configurationOverrides : undefined,
localizations: Object.keys(localizationOverrides || {}).length > 0 ? localizationOverrides : undefined,
stylingVariables: Object.keys(stylingOverrides).length > 0 ? stylingOverrides : undefined
};
} as const satisfies StateOverride;
return {
...state,
...stateOverrides
Expand Down
4 changes: 2 additions & 2 deletions apps/showcase/e2e-playwright/sanity/lighthouse-sanity.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '../../src/app/app.fixture';

const baseUrl = process.env.PLAYWRIGHT_TARGET_URL || 'http://localhost:4200/';
const lighthouseConfig: playwrightLighthouseConfig = {
const lighthouseConfig = {
thresholds: {
// Disable performance measurement because it is too unreliable in the current setup
performance: 0,
Expand All @@ -32,7 +32,7 @@ const lighthouseConfig: playwrightLighthouseConfig = {
directory: 'playwright-reports/lighthouse'
},
port: 9222
};
} as const satisfies playwrightLighthouseConfig;

const performAudit = async (name: string, page: Page | string, testInfo: TestInfo) => {
const { playAudit } = await import('playwright-lighthouse');
Expand Down
4 changes: 2 additions & 2 deletions apps/showcase/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ import {
AppComponent,
} from './app.component';

const runtimeChecks: Partial<RuntimeChecks> = {
const runtimeChecks = {
strictActionImmutability: false,
strictActionSerializability: false,
strictActionTypeUniqueness: !isDevMode(),
strictActionWithinNgZone: !isDevMode(),
strictStateImmutability: !isDevMode(),
strictStateSerializability: false
};
} as const satisfies Partial<RuntimeChecks>;

registerLocaleData(localeEN, 'en-GB');
registerLocaleData(localeFR, 'fr-FR');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ import {
ConfigurationPresConfig,
} from '../../components/showcase/configuration/configuration-pres.config';

const CONFIG_OVERRIDE: ConfigurationPresConfig = {
const CONFIG_OVERRIDE = {
inXDays: 30,
destinations: [
{ cityName: 'Manchester', available: true },
{ cityName: 'Nice', available: true },
{ cityName: 'Dallas', available: true }
],
shouldProposeRoundTrip: true
};
} as const satisfies ConfigurationPresConfig;

@O3rComponent({ componentType: 'Page' })
@Component({
Expand Down
6 changes: 2 additions & 4 deletions apps/showcase/src/app/rules-engine/rules-engine.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ import {
import {
CurrentTimeFactsService,
dateInNextMinutes,
Operator,
Rule,
RulesEngineDevtoolsModule,
RulesEngineRunnerModule,
RulesEngineRunnerService,
Ruleset,
UnaryOperator,
} from '@o3r/rules-engine';
import {
firstValueFrom,
Expand Down Expand Up @@ -137,8 +135,8 @@ export class RulesEngineComponent implements AfterViewInit {
inject(AssetRulesEngineActionHandler),
inject(LocalizationRulesEngineActionHandler)
);
this.rulesEngineService.engine.upsertOperators([duringSummer] as UnaryOperator[]);
this.rulesEngineService.engine.upsertOperators([dateInNextMinutes] as Operator[]);
this.rulesEngineService.engine.upsertOperators([duringSummer]);
this.rulesEngineService.engine.upsertOperators([dateInNextMinutes]);
inject(TripFactsService).register();
const currentTimeFactsService = inject(CurrentTimeFactsService);
currentTimeFactsService.register();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ export interface ConfigurationPresConfig extends Configuration {
shouldProposeRoundTrip: boolean;
}

export const CONFIGURATION_PRES_DEFAULT_CONFIG: ConfigurationPresConfig = {
export const CONFIGURATION_PRES_DEFAULT_CONFIG: Readonly<ConfigurationPresConfig> = {
inXDays: 7,
destinations: [
{ cityName: 'London', available: true },
{ cityName: 'Paris', available: true },
{ cityName: 'New-York', available: false }
],
shouldProposeRoundTrip: false
};
} as const;

export const CONFIGURATION_PRES_CONFIG_ID = computeItemIdentifier('ConfigurationPresConfig', 'showcase');
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export interface LocalizationPresTranslation extends Translation {
cityName: string;
}

export const translations: LocalizationPresTranslation = {
export const translations: Readonly<LocalizationPresTranslation> = {
welcome: 'o3r-localization-pres.welcome',
welcomeWithCityName: 'o3r-localization-pres.welcomeWithCityName',
question: 'o3r-localization-pres.question',
destinationLabel: 'o3r-localization-pres.destinationLabel',
departureLabel: 'o3r-localization-pres.departureLabel',
cityName: 'o3r-localization-pres.cityName',
destinationPlaceholder: 'o3r-localization-pres.destinationPlaceholder'
};
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export interface RulesEnginePresConfig extends Configuration {
shouldProposeRoundTrip: boolean;
}

export const RULES_ENGINE_PRES_DEFAULT_CONFIG: RulesEnginePresConfig = {
export const RULES_ENGINE_PRES_DEFAULT_CONFIG: Readonly<RulesEnginePresConfig> = {
inXDays: 7,
destinations: [
{ cityCode: 'LON', available: true },
{ cityCode: 'PAR', available: true },
{ cityCode: 'NYC', available: false }
],
shouldProposeRoundTrip: false
};
} as const;

export const RULES_ENGINE_PRES_CONFIG_ID = computeItemIdentifier('RulesEnginePresConfig', 'showcase');
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface RulesEnginePresTranslation extends Translation {
*/
returnLabel: string;
}
export const translations: RulesEnginePresTranslation = {
export const translations: Readonly<RulesEnginePresTranslation> = {
welcome: 'o3r-rules-engine-pres.welcome',
welcomeWithCityName: 'o3r-rules-engine-pres.welcomeWithCityName',
question: 'o3r-rules-engine-pres.question',
Expand All @@ -45,4 +45,4 @@ export const translations: RulesEnginePresTranslation = {
cityName: 'o3r-rules-engine-pres.cityName',
returnLabel: 'o3r-rules-engine-pres.returnLabel',
destinationPlaceholder: 'o3r-rules-engine-pres.destinationPlaceholder'
};
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ export class SdkPresComponent {
* Call the API to create a new pet
*/
public async create() {
const pet: Pet = {
const pet = {

Check warning on line 165 in apps/showcase/src/components/showcase/sdk/sdk-pres.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/showcase/src/components/showcase/sdk/sdk-pres.component.ts#L165

Added line #L165 was not covered by tests
id: this.getNextId(),
name: this.petName(),
category: { name: 'otter' },
tags: [{ name: 'otter' }],
status: 'available',
photoUrls: this.petName() ? [this.petImage()] : []
};
} as const satisfies Pet;
this.isLoading.set(true);
await this.petStoreApi.addPet({

Expand All @@ -179,7 +179,7 @@ export class SdkPresComponent {
const filePath = `${this.baseUrl}${pet.photoUrls[0]}`;
const blob = await (await fetch(filePath)).blob();
await this.petStoreApi.uploadFile({
petId: pet.id!,
petId: pet.id,
body: new File([blob], filePath, { type: blob.type })
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@ama-sdk/client-angular/src/api-angular-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export interface BaseApiAngularClientOptions extends BaseApiClientOptions {
export interface BaseApiAngularClientConstructor extends PartialExcept<BaseApiAngularClientOptions, 'basePath' | 'httpClient'> {
}

const DEFAULT_OPTIONS: Omit<BaseApiAngularClientOptions, 'basePath' | 'httpClient'> = {
const DEFAULT_OPTIONS = {
replyPlugins: [new ReviverReply(), new ExceptionReply()],
angularPlugins: [],
requestPlugins: [],
enableTokenization: false,
disableFallback: false
};
} as const satisfies Omit<BaseApiAngularClientOptions, 'basePath' | 'httpClient'>;

/** Client to process the call to the API using Angular API */
export class ApiAngularClient implements ApiClient {
Expand Down
4 changes: 2 additions & 2 deletions packages/@ama-sdk/client-beacon/src/api-beacon-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export interface BaseApiBeaconClientOptions extends BaseApiClientOptions {
export interface BaseApiBeaconClientConstructor extends PartialExcept<Omit<BaseApiBeaconClientOptions, 'replyPlugins'>, 'basePath'> {
}

const DEFAULT_OPTIONS: Omit<BaseApiBeaconClientOptions, 'basePath'> = {
const DEFAULT_OPTIONS = {
replyPlugins: [] as never[],
requestPlugins: [],
enableTokenization: false
};
} as const satisfies Omit<BaseApiBeaconClientOptions, 'basePath'>;

/**
* Determine if the given value is a promise
Expand Down
4 changes: 2 additions & 2 deletions packages/@ama-sdk/client-fetch/src/api-fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export interface BaseApiFetchClientOptions extends BaseApiClientOptions {
export interface BaseApiFetchClientConstructor extends PartialExcept<BaseApiFetchClientOptions, 'basePath'> {
}

const DEFAULT_OPTIONS: Omit<BaseApiFetchClientOptions, 'basePath'> = {
const DEFAULT_OPTIONS = {
replyPlugins: [new ReviverReply(), new ExceptionReply()],
fetchPlugins: [],
requestPlugins: [],
enableTokenization: false,
disableFallback: false
};
} as const satisfies Omit<BaseApiFetchClientOptions, 'basePath'>;

/** Client to process the call to the API using Fetch API */
export class ApiFetchClient implements ApiClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ export class PerformanceMetricPlugin implements FetchPlugin {
const markId = v4();
const perfMark = this.performance?.mark(this.getPerformanceTag('start', markId)) || undefined;
const startTime = perfMark?.startTime ?? this.getTime();
const mark: Mark = {
const mark = {
markId,
url,
requestOptions,
startTime
};
} as const satisfies Mark;
this.openMarks[markId] = mark;
if (this.onMarkOpen) {
void this.onMarkOpen(mark);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ export class RawResponseInfoReply<V = { [key: string]: any } | undefined> implem
return data;
}

const responseInfo: RawResponseReply = {
const responseInfo = {
responseInfo: {
...context.response,
apiType: context.apiType,
apiName: context.apiName
}
};
} as const satisfies RawResponseReply;

return data ? Object.assign(data, responseInfo) : responseInfo as V & RawResponseReply;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@ama-sdk/core/src/plugins/reviver/reviver.reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class ReviverReply<V = { [key: string]: any }> implements ReplyPlugin<und
constructor(public readonly options?: ReviverOptions) {}

public load<K>(context: ReplyPluginContext<K>): PluginRunner<K | undefined, V> {
const options: ReviverOptions = {
const options = {
logger: context.logger,
...this.options
};
} as const satisfies ReviverOptions;

return {
transform: (data?: V) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export interface SimpleApiKeyAuthenticationRequestOptions {
/**
* Default values of optional parameters
*/
const DEFAULT_OPTION: SimpleApiKeyAuthenticationRequestOptions = {
const DEFAULT_OPTION = {
apiKeyHeader: 'x-api-key',
contextHeader: 'ama-ctx'
};
} as const satisfies SimpleApiKeyAuthenticationRequestOptions;

/**
* Plugin to handle the Simple API key authentication with Apigee.
Expand Down
8 changes: 4 additions & 4 deletions packages/@ama-sdk/core/src/utils/generic-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ export class GenericApi implements Api {
*/
public async request<T>(requestOptions: GenericRequestOptions<T>): Promise<T> {
const metadataHeaderAccept = requestOptions.metadata?.headerAccept || 'application/json';
const headers: { [key: string]: string | undefined } = {
const headers = {

Check warning on line 50 in packages/@ama-sdk/core/src/utils/generic-api.ts

View check run for this annotation

Codecov / codecov/patch

packages/@ama-sdk/core/src/utils/generic-api.ts#L50

Added line #L50 was not covered by tests
'Content-Type': requestOptions.metadata?.headerContentType || 'application/json',
...(metadataHeaderAccept ? { Accept: metadataHeaderAccept } : {})
};
} as const satisfies RequestOptionsParameters['headers'];

const requestParameters: RequestOptionsParameters = {
const requestParameters = {

Check warning on line 55 in packages/@ama-sdk/core/src/utils/generic-api.ts

View check run for this annotation

Codecov / codecov/patch

packages/@ama-sdk/core/src/utils/generic-api.ts#L55

Added line #L55 was not covered by tests
api: this,
headers,
...requestOptions
};
} as const satisfies RequestOptionsParameters;
const options = await this.client.getRequestOptions(requestParameters);
const url = this.client.prepareUrl(options.basePath, options.queryParams);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export abstract class CodeGenerator<T extends CodegenTaskOptions> {
*/
private getTaskConfiguration(options: Partial<T>): TaskConfigurationGenerator<T> {
const name = this.generatorName;
const opts: T = { ...this.getDefaultOptions(), ...options };
const opts = { ...this.getDefaultOptions(), ...options } as const satisfies T;
return new (class implements TaskConfigurationGenerator<T> {
public toConfiguration(): TaskConfiguration<T> {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ export class OpenApiCliGenerator extends CodeGenerator<OpenApiCliOptions> {
if (!generatorOptions) {
return Promise.reject(new Error('Missing options to run open api generator'));
}
const spawnOptions: SpawnOptions = {
const spawnOptions = {

Check warning on line 99 in packages/@ama-sdk/schematics/schematics/code-generator/open-api-cli-generator/open-api-cli.generator.ts

View check run for this annotation

Codecov / codecov/patch

packages/@ama-sdk/schematics/schematics/code-generator/open-api-cli-generator/open-api-cli.generator.ts#L99

Added line #L99 was not covered by tests
stdio: 'inherit',
shell: true,
cwd: rootDirectory
};
} as const satisfies SpawnOptions;
if (generatorOptions.generatorVersion) {
await this.runInstallOpenApiGenerator(generatorOptions.generatorVersion, spawnOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type OpenApiCliOptions = CodegenTaskOptions & {
/**
* Default options to run our custom typescript generator
*/
export const defaultTypescriptGeneratorOptions: OpenApiCliOptions = {
export const defaultTypescriptGeneratorOptions: Readonly<OpenApiCliOptions> = {
generatorVersion: '',
generatorName: 'typescriptFetch',
generatorCustomPath: path.join(__dirname, '..', '..', 'typescript', 'core', 'openapi-codegen-typescript', 'target', 'typescriptFetch-openapi-generator.jar'),
Expand All @@ -72,4 +72,4 @@ export const defaultTypescriptGeneratorOptions: OpenApiCliOptions = {
globalProperty: '',
generatorKey: '',
openapiNormalizer: ''
};
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export class SwaggerJavaGenerator extends CodeGenerator<JavaGeneratorTaskOptions
if (!generatorOptions) {
return Promise.reject(new Error('Missing options'));
}
const spawnOptions: SpawnOptions = {
const spawnOptions = {

Check warning on line 31 in packages/@ama-sdk/schematics/schematics/code-generator/swagger-java-generator/swagger-java.generator.ts

View check run for this annotation

Codecov / codecov/patch

packages/@ama-sdk/schematics/schematics/code-generator/swagger-java-generator/swagger-java.generator.ts#L31

Added line #L31 was not covered by tests
stdio: 'inherit',
shell: true,
cwd: rootDirectory
};
} as const satisfies SpawnOptions;
const codegenPath = path.join(generatorOptions.targetFolder, `${generatorOptions.codegenLanguage}-${generatorOptions.codegenFileName}`);
const cliPath = path.resolve(__dirname, '..', '..', 'resources', generatorOptions.cliFilename);

Expand Down
Loading

0 comments on commit 1603bff

Please sign in to comment.