Skip to content

Commit

Permalink
Updated TypeScript types style
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime committed Nov 2, 2024
1 parent bf3cb5d commit 7072129
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
20 changes: 10 additions & 10 deletions packages/~feature-hub/src/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, string | null>>;

export interface CompatibilityInfo
{
Expand Down Expand Up @@ -40,14 +40,14 @@ export interface FeatureConstructor
(...features: FeatureElementOrCompatibleArray[]): Feature;

readonly ALL:
{ readonly [FeatureName in string]: PredefinedFeature; };
Readonly<Record<string, PredefinedFeature>>;

readonly ELEMENTARY: readonly PredefinedFeature[];

readonly ENGINE: readonly PredefinedFeature[];

readonly FAMILIES:
{ readonly [Family in string]: readonly CompatibilityInfo[]; };
Readonly<Record<string, CompatibilityInfo[]>>;

new (...features: FeatureElementOrCompatibleArray[]): Feature;
_fromMask(mask: Mask): Feature | null;
Expand All @@ -71,7 +71,7 @@ export type FeatureInfo =
readonly aliasFor: string;
} |
{
readonly attributes?: { readonly [AttributeName in string]: string | null | undefined; };
readonly attributes?: Readonly<Record<string, string | null | undefined>>;
readonly check?: () => unknown;
readonly excludes?: readonly string[];
readonly includes?: readonly string[] | IncludeDifferenceMap;
Expand All @@ -82,7 +82,7 @@ export type FeatureInfo =
) &
{ readonly description?: string; };

export type IncludeDifferenceMap = { readonly [FeatureName in string]: boolean; };
export type IncludeDifferenceMap = Readonly<Record<string, boolean>>;

export interface PredefinedFeature extends Feature
{
Expand Down Expand Up @@ -122,7 +122,7 @@ function assignNoEnum(target: object, source: object): void

export function createFeatureClass
(
featureInfos: { readonly [FeatureName in string]: FeatureInfo; },
featureInfos: Readonly<Record<string, FeatureInfo>>,
formatEngineDescription?: (compatibilities: CompatibilityInfo[]) => string,
):
FeatureConstructor
Expand Down Expand Up @@ -436,7 +436,7 @@ FeatureConstructor
const str = `[Feature ${name}]`;
return str;
},
} as { [PropName in string]: unknown; } & ThisType<Feature>;
} as Record<string, unknown> & ThisType<Feature>;
if (utilInspect)
protoSource.inspect = inspect;
assignNoEnum(FEATURE_PROTOTYPE, protoSource);
Expand Down Expand Up @@ -483,7 +483,7 @@ FeatureConstructor
const getInfoStringField =
<FieldNameType extends string>(fieldName: FieldNameType): string | undefined =>
fieldName in info ?
esToString((info as { [Name in FieldNameType]: unknown; })[fieldName]) : undefined;
esToString((info as Record<FieldNameType, unknown>)[fieldName]) : undefined;
let description = getInfoStringField('description');
let featureObj: PredefinedFeature;
if ('aliasFor' in info)
Expand Down Expand Up @@ -655,7 +655,7 @@ FeatureConstructor
}

const featureNames = _Object_keys(featureInfos);
const includeSetMap = createMap<{ readonly [FeatureName in string]: null; }>();
const includeSetMap = createMap<Readonly<Record<string, null>>>();
const familiesMap = createMap<readonly string[]>();
let unionMask = MASK_EMPTY;

Expand All @@ -676,7 +676,7 @@ FeatureConstructor
return Feature as FeatureConstructor;
}

const createMap = <T>(): { [Key in string]: T; } => _Object_create(null) as { };
const createMap = <T>(): Record<string, T> => _Object_create(null) as { };

function esToString(name: unknown): string
{
Expand Down
2 changes: 1 addition & 1 deletion packages/~feature-hub/src/mask-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const keyFor = (mask: Mask): string => `_${mask as never as number}`;

class MaskIndex<ValueType>
{
protected readonly _index = Object.create(null) as { [KeyType in string]?: ValueType; };
protected readonly _index = Object.create(null) as Record<string, ValueType>;
private _size = 0;

/* The number of entries in the current collection. */
Expand Down
4 changes: 2 additions & 2 deletions packages/~feature-hub/test/spec/feature.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string | null>;
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<string, string | null>;
expected.id = 'bar';
expected.bar = null;
assert.deepStrictEqual(BAR.attributes, expected);
Expand Down
1 change: 1 addition & 0 deletions packages/~feature-hub/test/spec/mask.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 7072129

Please sign in to comment.