Skip to content

Commit 6591581

Browse files
committed
Simplify record types
1 parent 22d8296 commit 6591581

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

node_package/src/Authenticity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
return null;
1010
},
1111

12-
authenticityHeaders(otherHeaders: { [id: string]: string } = {}): AuthenticityHeaders {
12+
authenticityHeaders(otherHeaders: Record<string, string> = {}): AuthenticityHeaders {
1313
return Object.assign(otherHeaders, {
1414
'X-CSRF-Token': this.authenticityToken(),
1515
'X-Requested-With': 'XMLHttpRequest',

node_package/src/ComponentRegistry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
/**
99
* @param components { component1: component1, component2: component2, etc. }
1010
*/
11-
register(components: { [id: string]: ReactComponentOrRenderFunction }): void {
11+
register(components: Record<string, ReactComponentOrRenderFunction>): void {
1212
Object.keys(components).forEach((name) => {
1313
if (componentRegistry.has(name)) {
1414
console.warn('Called register for component that is already registered', name);

node_package/src/ReactOnRails.client.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ ctx.ReactOnRails = {
4646
* find you components for rendering.
4747
* @param components (key is component name, value is component)
4848
*/
49-
register(components: { [id: string]: ReactComponentOrRenderFunction }): void {
49+
register(components: Record<string, ReactComponentOrRenderFunction>): void {
5050
ComponentRegistry.register(components);
5151
},
5252

53-
registerStore(stores: { [id: string]: StoreGenerator }): void {
53+
registerStore(stores: Record<string, StoreGenerator>): void {
5454
this.registerStoreGenerators(stores);
5555
},
5656

@@ -60,7 +60,7 @@ ctx.ReactOnRails = {
6060
* the setStore API is different in that it's the actual store hydrated with props.
6161
* @param storeGenerators (keys are store names, values are the store generators)
6262
*/
63-
registerStoreGenerators(storeGenerators: { [id: string]: StoreGenerator }): void {
63+
registerStoreGenerators(storeGenerators: Record<string, StoreGenerator>): void {
6464
if (!storeGenerators) {
6565
throw new Error(
6666
'Called ReactOnRails.registerStoreGenerators with a null or undefined, rather than ' +
@@ -172,7 +172,7 @@ ctx.ReactOnRails = {
172172
* @returns {*} header
173173
*/
174174

175-
authenticityHeaders(otherHeaders: { [id: string]: string } = {}): AuthenticityHeaders {
175+
authenticityHeaders(otherHeaders: Record<string, string> = {}): AuthenticityHeaders {
176176
return Authenticity.authenticityHeaders(otherHeaders);
177177
},
178178

node_package/src/StoreRegistry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
* Register a store generator, a function that takes props and returns a store.
1010
* @param storeGenerators { name1: storeGenerator1, name2: storeGenerator2 }
1111
*/
12-
register(storeGenerators: { [id: string]: StoreGenerator }): void {
12+
register(storeGenerators: Record<string, StoreGenerator>): void {
1313
Object.keys(storeGenerators).forEach((name) => {
1414
if (storeGeneratorRegistry.has(name)) {
1515
console.warn('Called registerStore for store that is already registered', name);

node_package/src/registerServerComponent/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { ReactComponent } from '../types';
3030
* });
3131
* ```
3232
*/
33-
const registerServerComponent = (components: { [id: string]: ReactComponent }) => {
33+
const registerServerComponent = (components: Record<string, ReactComponent>) => {
3434
ReactOnRails.register(components);
3535
};
3636

node_package/src/types/index.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export interface RailsContext {
3333
httpAcceptLanguage: string;
3434
}
3535

36-
type AuthenticityHeaders = { [id: string]: string } & {
36+
// not strictly what we want, see https://github.com/microsoft/TypeScript/issues/17867#issuecomment-323164375
37+
type AuthenticityHeaders = Record<string, string> & {
3738
'X-CSRF-Token': string | null;
3839
'X-Requested-With': string;
3940
};
@@ -167,10 +168,10 @@ export interface Root {
167168
export type RenderReturnType = void | Element | Component | Root;
168169

169170
export interface ReactOnRails {
170-
register(components: { [id: string]: ReactComponentOrRenderFunction }): void;
171+
register(components: Record<string, ReactComponentOrRenderFunction>): void;
171172
/** @deprecated Use registerStoreGenerators instead */
172-
registerStore(stores: { [id: string]: StoreGenerator }): void;
173-
registerStoreGenerators(storeGenerators: { [id: string]: StoreGenerator }): void;
173+
registerStore(stores: Record<string, StoreGenerator>): void;
174+
registerStoreGenerators(storeGenerators: Record<string, StoreGenerator>): void;
174175
getStore(name: string, throwIfMissing?: boolean): Store | undefined;
175176
getOrWaitForStore(name: string): Promise<Store>;
176177
getOrWaitForStoreGenerator(name: string): Promise<StoreGenerator>;
@@ -180,7 +181,7 @@ export interface ReactOnRails {
180181
reactOnRailsComponentLoaded(domId: string): void;
181182
reactOnRailsStoreLoaded(storeName: string): void;
182183
authenticityToken(): string | null;
183-
authenticityHeaders(otherHeaders: { [id: string]: string }): AuthenticityHeaders;
184+
authenticityHeaders(otherHeaders: Record<string, string>): AuthenticityHeaders;
184185
option(key: string): string | number | boolean | undefined;
185186
getStoreGenerator(name: string): StoreGenerator;
186187
setStore(name: string, store: Store): void;

0 commit comments

Comments
 (0)