Skip to content

Commit 7072129

Browse files
committed
Updated TypeScript types style
1 parent bf3cb5d commit 7072129

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

packages/~feature-hub/src/feature.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from './mask-impl';
55

66
import { MaskSet } from './mask-index';
77

8-
export type AttributeMap = { readonly [AttributeName in string]: string | null; };
8+
export type AttributeMap = Readonly<Record<string, string | null>>;
99

1010
export interface CompatibilityInfo
1111
{
@@ -40,14 +40,14 @@ export interface FeatureConstructor
4040
(...features: FeatureElementOrCompatibleArray[]): Feature;
4141

4242
readonly ALL:
43-
{ readonly [FeatureName in string]: PredefinedFeature; };
43+
Readonly<Record<string, PredefinedFeature>>;
4444

4545
readonly ELEMENTARY: readonly PredefinedFeature[];
4646

4747
readonly ENGINE: readonly PredefinedFeature[];
4848

4949
readonly FAMILIES:
50-
{ readonly [Family in string]: readonly CompatibilityInfo[]; };
50+
Readonly<Record<string, CompatibilityInfo[]>>;
5151

5252
new (...features: FeatureElementOrCompatibleArray[]): Feature;
5353
_fromMask(mask: Mask): Feature | null;
@@ -71,7 +71,7 @@ export type FeatureInfo =
7171
readonly aliasFor: string;
7272
} |
7373
{
74-
readonly attributes?: { readonly [AttributeName in string]: string | null | undefined; };
74+
readonly attributes?: Readonly<Record<string, string | null | undefined>>;
7575
readonly check?: () => unknown;
7676
readonly excludes?: readonly string[];
7777
readonly includes?: readonly string[] | IncludeDifferenceMap;
@@ -82,7 +82,7 @@ export type FeatureInfo =
8282
) &
8383
{ readonly description?: string; };
8484

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

8787
export interface PredefinedFeature extends Feature
8888
{
@@ -122,7 +122,7 @@ function assignNoEnum(target: object, source: object): void
122122

123123
export function createFeatureClass
124124
(
125-
featureInfos: { readonly [FeatureName in string]: FeatureInfo; },
125+
featureInfos: Readonly<Record<string, FeatureInfo>>,
126126
formatEngineDescription?: (compatibilities: CompatibilityInfo[]) => string,
127127
):
128128
FeatureConstructor
@@ -436,7 +436,7 @@ FeatureConstructor
436436
const str = `[Feature ${name}]`;
437437
return str;
438438
},
439-
} as { [PropName in string]: unknown; } & ThisType<Feature>;
439+
} as Record<string, unknown> & ThisType<Feature>;
440440
if (utilInspect)
441441
protoSource.inspect = inspect;
442442
assignNoEnum(FEATURE_PROTOTYPE, protoSource);
@@ -483,7 +483,7 @@ FeatureConstructor
483483
const getInfoStringField =
484484
<FieldNameType extends string>(fieldName: FieldNameType): string | undefined =>
485485
fieldName in info ?
486-
esToString((info as { [Name in FieldNameType]: unknown; })[fieldName]) : undefined;
486+
esToString((info as Record<FieldNameType, unknown>)[fieldName]) : undefined;
487487
let description = getInfoStringField('description');
488488
let featureObj: PredefinedFeature;
489489
if ('aliasFor' in info)
@@ -655,7 +655,7 @@ FeatureConstructor
655655
}
656656

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

@@ -676,7 +676,7 @@ FeatureConstructor
676676
return Feature as FeatureConstructor;
677677
}
678678

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

681681
function esToString(name: unknown): string
682682
{

packages/~feature-hub/src/mask-index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const keyFor = (mask: Mask): string => `_${mask as never as number}`;
44

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

1010
/* The number of entries in the current collection. */

packages/~feature-hub/test/spec/feature.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ it
8989
assert.deepStrictEqual(RED2.attributes, Object.create(null));
9090
assert.deepStrictEqual(GREEN.attributes, Object.create(null));
9191
{
92-
const expected = Object.create(null) as { [AttributeName in string]: string | null; };
92+
const expected = Object.create(null) as Record<string, string | null>;
9393
expected.id = 'foo';
9494
expected.foo = null;
9595
assert.deepStrictEqual(FOO.attributes, expected);
9696
}
9797
{
98-
const expected = Object.create(null) as { [AttributeName in string]: string | null; };
98+
const expected = Object.create(null) as Record<string, string | null>;
9999
expected.id = 'bar';
100100
expected.bar = null;
101101
assert.deepStrictEqual(BAR.attributes, expected);

packages/~feature-hub/test/spec/mask.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function assertMaskNotEmpty(actual: Mask): void
6262

6363
function formatMask(mask: Mask): string
6464
{
65+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
6566
const str = `mask ${String(mask)}`;
6667
return str;
6768
}

0 commit comments

Comments
 (0)