From 7072129a4eda7fe8e116bbbeedd08e27d7973ec8 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Sat, 2 Nov 2024 15:03:56 +0100 Subject: [PATCH] Updated TypeScript types style --- packages/~feature-hub/src/feature.ts | 20 +++++++++---------- packages/~feature-hub/src/mask-index.ts | 2 +- .../~feature-hub/test/spec/feature.spec.ts | 4 ++-- packages/~feature-hub/test/spec/mask.spec.ts | 1 + 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/~feature-hub/src/feature.ts b/packages/~feature-hub/src/feature.ts index 84f2c31f..5758271b 100644 --- a/packages/~feature-hub/src/feature.ts +++ b/packages/~feature-hub/src/feature.ts @@ -5,7 +5,7 @@ from './mask-impl'; import { MaskSet } from './mask-index'; -export type AttributeMap = { readonly [AttributeName in string]: string | null; }; +export type AttributeMap = Readonly>; export interface CompatibilityInfo { @@ -40,14 +40,14 @@ export interface FeatureConstructor (...features: FeatureElementOrCompatibleArray[]): Feature; readonly ALL: - { readonly [FeatureName in string]: PredefinedFeature; }; + Readonly>; readonly ELEMENTARY: readonly PredefinedFeature[]; readonly ENGINE: readonly PredefinedFeature[]; readonly FAMILIES: - { readonly [Family in string]: readonly CompatibilityInfo[]; }; + Readonly>; new (...features: FeatureElementOrCompatibleArray[]): Feature; _fromMask(mask: Mask): Feature | null; @@ -71,7 +71,7 @@ export type FeatureInfo = readonly aliasFor: string; } | { - readonly attributes?: { readonly [AttributeName in string]: string | null | undefined; }; + readonly attributes?: Readonly>; readonly check?: () => unknown; readonly excludes?: readonly string[]; readonly includes?: readonly string[] | IncludeDifferenceMap; @@ -82,7 +82,7 @@ export type FeatureInfo = ) & { readonly description?: string; }; -export type IncludeDifferenceMap = { readonly [FeatureName in string]: boolean; }; +export type IncludeDifferenceMap = Readonly>; export interface PredefinedFeature extends Feature { @@ -122,7 +122,7 @@ function assignNoEnum(target: object, source: object): void export function createFeatureClass ( - featureInfos: { readonly [FeatureName in string]: FeatureInfo; }, + featureInfos: Readonly>, formatEngineDescription?: (compatibilities: CompatibilityInfo[]) => string, ): FeatureConstructor @@ -436,7 +436,7 @@ FeatureConstructor const str = `[Feature ${name}]`; return str; }, - } as { [PropName in string]: unknown; } & ThisType; + } as Record & ThisType; if (utilInspect) protoSource.inspect = inspect; assignNoEnum(FEATURE_PROTOTYPE, protoSource); @@ -483,7 +483,7 @@ FeatureConstructor const getInfoStringField = (fieldName: FieldNameType): string | undefined => fieldName in info ? - esToString((info as { [Name in FieldNameType]: unknown; })[fieldName]) : undefined; + esToString((info as Record)[fieldName]) : undefined; let description = getInfoStringField('description'); let featureObj: PredefinedFeature; if ('aliasFor' in info) @@ -655,7 +655,7 @@ FeatureConstructor } const featureNames = _Object_keys(featureInfos); - const includeSetMap = createMap<{ readonly [FeatureName in string]: null; }>(); + const includeSetMap = createMap>>(); const familiesMap = createMap(); let unionMask = MASK_EMPTY; @@ -676,7 +676,7 @@ FeatureConstructor return Feature as FeatureConstructor; } -const createMap = (): { [Key in string]: T; } => _Object_create(null) as { }; +const createMap = (): Record => _Object_create(null) as { }; function esToString(name: unknown): string { diff --git a/packages/~feature-hub/src/mask-index.ts b/packages/~feature-hub/src/mask-index.ts index bd126a8b..406a204c 100644 --- a/packages/~feature-hub/src/mask-index.ts +++ b/packages/~feature-hub/src/mask-index.ts @@ -4,7 +4,7 @@ const keyFor = (mask: Mask): string => `_${mask as never as number}`; class MaskIndex { - protected readonly _index = Object.create(null) as { [KeyType in string]?: ValueType; }; + protected readonly _index = Object.create(null) as Record; private _size = 0; /* The number of entries in the current collection. */ diff --git a/packages/~feature-hub/test/spec/feature.spec.ts b/packages/~feature-hub/test/spec/feature.spec.ts index d7d47cd3..8744e7d4 100644 --- a/packages/~feature-hub/test/spec/feature.spec.ts +++ b/packages/~feature-hub/test/spec/feature.spec.ts @@ -89,13 +89,13 @@ it assert.deepStrictEqual(RED2.attributes, Object.create(null)); assert.deepStrictEqual(GREEN.attributes, Object.create(null)); { - const expected = Object.create(null) as { [AttributeName in string]: string | null; }; + const expected = Object.create(null) as Record; expected.id = 'foo'; expected.foo = null; assert.deepStrictEqual(FOO.attributes, expected); } { - const expected = Object.create(null) as { [AttributeName in string]: string | null; }; + const expected = Object.create(null) as Record; expected.id = 'bar'; expected.bar = null; assert.deepStrictEqual(BAR.attributes, expected); diff --git a/packages/~feature-hub/test/spec/mask.spec.ts b/packages/~feature-hub/test/spec/mask.spec.ts index 20ba8a35..205ed04f 100644 --- a/packages/~feature-hub/test/spec/mask.spec.ts +++ b/packages/~feature-hub/test/spec/mask.spec.ts @@ -62,6 +62,7 @@ function assertMaskNotEmpty(actual: Mask): void function formatMask(mask: Mask): string { + // eslint-disable-next-line @typescript-eslint/no-base-to-string const str = `mask ${String(mask)}`; return str; }