Use Record type (#7798)

This commit is contained in:
Paulus Schoutsen 2020-11-25 10:40:32 +01:00 committed by GitHub
parent f6cb1ffe20
commit 1d13947e71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 45 additions and 45 deletions

View File

@ -9,5 +9,5 @@ export interface DemoConfig {
authorUrl: string;
lovelace: (localize: LocalizeFunc) => LovelaceConfig;
entities: (localize: LocalizeFunc) => Entity[];
theme: () => { [key: string]: string } | null;
theme: () => Record<string, string> | null;
}

View File

@ -13,10 +13,10 @@ import { rgbContrast } from "../color/rgb";
interface ProcessedTheme {
keys: { [key: string]: "" };
styles: { [key: string]: string };
styles: Record<string, string>;
}
let PROCESSED_THEMES: { [key: string]: ProcessedTheme } = {};
let PROCESSED_THEMES: Record<string, ProcessedTheme> = {};
/**
* Apply a theme to an element by setting the CSS variables on it.

View File

@ -1,7 +1,7 @@
import { directive, NodePart, Part } from "lit-html";
export const dynamicElement = directive(
(tag: string, properties?: { [key: string]: any }) => (part: Part): void => {
(tag: string, properties?: Record<string, any>) => (part: Part): void => {
if (!(part instanceof NodePart)) {
throw new Error(
"dynamicElementDirective can only be used in content bindings"

View File

@ -102,7 +102,7 @@ export const computeLocalize = async (
export const localizeKey = (
localize: LocalizeFunc,
key: string,
placeholders?: { [key: string]: string }
placeholders?: Record<string, string>
) => {
const args: [string, ...string[]] = [key];
if (placeholders) {

View File

@ -1,4 +1,4 @@
export const extractSearchParamsObject = (): { [key: string]: string } => {
export const extractSearchParamsObject = (): Record<string, string> => {
const query = {};
const searchParams = new URLSearchParams(location.search);
for (const [key, value] of searchParams.entries()) {

View File

@ -54,7 +54,7 @@ export interface HaFormSelectSchema extends HaFormBaseSchema {
export interface HaFormMultiSelectSchema extends HaFormBaseSchema {
type: "multi_select";
options?: { [key: string]: string } | string[] | Array<[string, string]>;
options?: Record<string, string> | string[] | Array<[string, string]>;
}
export interface HaFormFloatSchema extends HaFormBaseSchema {

View File

@ -39,7 +39,7 @@ checkCacheVersion();
const debouncedWriteCache = debounce(() => writeCache(chunks), 2000);
const cachedIcons: { [key: string]: string } = {};
const cachedIcons: Record<string, string> = {};
@customElement("ha-icon")
export class HaIcon extends LitElement {

View File

@ -66,7 +66,7 @@ export class HaLocationsEditor extends LitElement {
private _locationMarkers?: { [key: string]: Marker | Circle };
private _circles: { [key: string]: Circle } = {};
private _circles: Record<string, Circle> = {};
public fitMap(): void {
if (

View File

@ -31,7 +31,7 @@ export const fetchConfigFlow = (hass: HomeAssistant, flowId: string) =>
export const handleConfigFlowStep = (
hass: HomeAssistant,
flowId: string,
data: { [key: string]: any }
data: Record<string, any>
) =>
hass.callApi<DataEntryFlowStep>(
"POST",

View File

@ -1,7 +1,7 @@
import { HomeAssistant } from "../types";
interface ProcessResults {
card: { [key: string]: { [key: string]: string } };
card: { [key: string]: Record<string, string> };
speech: {
[SpeechType in "plain" | "ssml"]: { extra_data: any; speech: string };
};

View File

@ -14,7 +14,7 @@ export interface DataEntryFlowProgress {
handler: string;
step_id: string;
context: {
title_placeholders: { [key: string]: string };
title_placeholders: Record<string, string>;
[key: string]: any;
};
}
@ -25,8 +25,8 @@ export interface DataEntryFlowStepForm {
handler: string;
step_id: string;
data_schema: HaFormSchema[];
errors: { [key: string]: string };
description_placeholders: { [key: string]: string };
errors: Record<string, string>;
description_placeholders: Record<string, string>;
}
export interface DataEntryFlowStepExternal {
@ -35,7 +35,7 @@ export interface DataEntryFlowStepExternal {
handler: string;
step_id: string;
url: string;
description_placeholders: { [key: string]: string };
description_placeholders: Record<string, string>;
}
export interface DataEntryFlowStepCreateEntry {
@ -47,7 +47,7 @@ export interface DataEntryFlowStepCreateEntry {
// Config entry ID
result: string;
description: string;
description_placeholders: { [key: string]: string };
description_placeholders: Record<string, string>;
}
export interface DataEntryFlowStepAbort {
@ -55,7 +55,7 @@ export interface DataEntryFlowStepAbort {
flow_id: string;
handler: string;
reason: string;
description_placeholders: { [key: string]: string };
description_placeholders: Record<string, string>;
}
export interface DataEntryFlowStepProgress {
@ -64,7 +64,7 @@ export interface DataEntryFlowStepProgress {
handler: string;
step_id: string;
progress_action: string;
description_placeholders: { [key: string]: string };
description_placeholders: Record<string, string>;
}
export type DataEntryFlowStep =

View File

@ -8,8 +8,8 @@ export interface HassioHardwareAudioDevice {
interface HassioHardwareAudioList {
audio: {
input: { [key: string]: string };
output: { [key: string]: string };
input: Record<string, string>;
output: Record<string, string>;
};
}

View File

@ -19,7 +19,7 @@ const LINE_ATTRIBUTES_TO_KEEP = [
export interface LineChartState {
state: string;
last_changed: string;
attributes?: { [key: string]: any };
attributes?: Record<string, any>;
}
export interface LineChartEntity {

View File

@ -20,7 +20,7 @@ export const fetchOptionsFlow = (hass: HomeAssistant, flowId: string) =>
export const handleOptionsFlowStep = (
hass: HomeAssistant,
flowId: string,
data: { [key: string]: any }
data: Record<string, any>
) =>
hass.callApi<DataEntryFlowStep>(
"POST",

View File

@ -29,14 +29,14 @@ export interface ScriptConfig {
export interface EventAction {
event: string;
event_data?: { [key: string]: any };
event_data_template?: { [key: string]: any };
event_data?: Record<string, any>;
event_data_template?: Record<string, any>;
}
export interface ServiceAction {
service: string;
entity_id?: string;
data?: { [key: string]: any };
data?: Record<string, any>;
}
export interface DeviceAction {

View File

@ -23,7 +23,7 @@ export interface FlowConfig {
handleFlowStep(
hass: HomeAssistant,
flowId: string,
data: { [key: string]: any }
data: Record<string, any>
): Promise<DataEntryFlowStep>;
deleteFlow(hass: HomeAssistant, flowId: string): Promise<unknown>;

View File

@ -34,7 +34,7 @@ class StepFlowForm extends LitElement {
private _loading = false;
@property()
private _stepData?: { [key: string]: any };
private _stepData?: Record<string, any>;
@property()
private _errorMsg?: string;

View File

@ -40,7 +40,7 @@ type ExternalMessage = ExternalMessageResult | ExternalMessageResultError;
export class ExternalMessaging {
public commands: { [msgId: number]: CommandInFlight } = {};
public cache: { [key: string]: any } = {};
public cache: Record<string, any> = {};
public msgId = 0;

View File

@ -21,9 +21,9 @@ export class Entity {
public state: string;
public baseAttributes: HassEntityAttributeBase & { [key: string]: any };
public baseAttributes: HassEntityAttributeBase & Record<string, any>;
public attributes: HassEntityAttributeBase & { [key: string]: any };
public attributes: HassEntityAttributeBase & Record<string, any>;
public hass?: any;
@ -39,7 +39,7 @@ export class Entity {
this.attributes = baseAttributes;
}
public async handleService(domain, service, data: { [key: string]: any }) {
public async handleService(domain, service, data: Record<string, any>) {
// eslint-disable-next-line
console.log(
`Unmocked service for ${this.entityId}: ${domain}/${service}`,

View File

@ -20,7 +20,7 @@ type MockRestCallback = (
hass: MockHomeAssistant,
method: string,
path: string,
parameters: { [key: string]: any } | undefined
parameters: Record<string, any> | undefined
) => any;
export interface MockHomeAssistant extends HomeAssistant {
@ -35,7 +35,7 @@ export interface MockHomeAssistant extends HomeAssistant {
);
mockAPI(path: string | RegExp, callback: MockRestCallback);
mockEvent(event);
mockTheme(theme: { [key: string]: string } | null);
mockTheme(theme: Record<string, string> | null);
}
export const provideHass = (

View File

@ -40,7 +40,7 @@ export class HaDeviceAction extends LitElement {
private _extraFieldsData = memoizeOne(
(action: DeviceAction, capabilities: DeviceCapabilities) => {
const extraFieldsData: { [key: string]: any } = {};
const extraFieldsData: Record<string, any> = {};
capabilities.extra_fields.forEach((item) => {
if (action[item.name] !== undefined) {
extraFieldsData![item.name] = action[item.name];

View File

@ -40,7 +40,7 @@ export class HaDeviceCondition extends LitElement {
private _extraFieldsData = memoizeOne(
(condition: DeviceCondition, capabilities: DeviceCapabilities) => {
const extraFieldsData: { [key: string]: any } = {};
const extraFieldsData: Record<string, any> = {};
capabilities.extra_fields.forEach((item) => {
if (condition[item.name] !== undefined) {
extraFieldsData![item.name] = condition[item.name];

View File

@ -40,7 +40,7 @@ export class HaDeviceTrigger extends LitElement {
private _extraFieldsData = memoizeOne(
(trigger: DeviceTrigger, capabilities: DeviceCapabilities) => {
const extraFieldsData: { [key: string]: any } = {};
const extraFieldsData: Record<string, any> = {};
capabilities.extra_fields.forEach((item) => {
if (trigger[item.name] !== undefined) {
extraFieldsData![item.name] = trigger[item.name];

View File

@ -56,7 +56,7 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard {
private _configEntities?: EntityConfig[];
private _names: { [key: string]: string } = {};
private _names: Record<string, string> = {};
private _cacheConfig?: CacheConfig;

View File

@ -111,7 +111,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
private _mapPaths: Array<Polyline | CircleMarker> = [];
private _colorDict: { [key: string]: string } = {};
private _colorDict: Record<string, string> = {};
private _colorIndex = 0;

View File

@ -17,7 +17,7 @@ export interface EntityFilterEntityConfig extends EntityConfig {
}
export interface DividerConfig {
type: "divider";
style: { [key: string]: string };
style: Record<string, string>;
}
export interface SectionConfig {
type: "section";
@ -38,7 +38,7 @@ export interface TextConfig {
export interface CallServiceConfig extends EntityConfig {
type: "call-service";
service: string;
service_data?: { [key: string]: any };
service_data?: Record<string, any>;
action_name?: string;
}
export interface ButtonRowConfig extends EntityConfig {

View File

@ -98,7 +98,7 @@ export interface Theme {
export interface Themes {
default_theme: string;
default_dark_theme: string | null;
themes: { [key: string]: Theme };
themes: Record<string, Theme>;
darkMode: boolean;
}
@ -188,7 +188,7 @@ export interface Notification {
}
export interface Resources {
[language: string]: { [key: string]: string };
[language: string]: Record<string, string>;
}
export interface Context {
@ -204,7 +204,7 @@ export interface ServiceCallResponse {
export interface ServiceCallRequest {
domain: string;
service: string;
serviceData?: { [key: string]: any };
serviceData?: Record<string, any>;
}
export interface HomeAssistant {
@ -248,9 +248,9 @@ export interface HomeAssistant {
callApi<T>(
method: "GET" | "POST" | "PUT" | "DELETE",
path: string,
parameters?: { [key: string]: any }
parameters?: Record<string, any>
): Promise<T>;
fetchWithAuth(path: string, init?: { [key: string]: any }): Promise<Response>;
fetchWithAuth(path: string, init?: Record<string, any>): Promise<Response>;
sendWS(msg: MessageBase): void;
callWS<T>(msg: MessageBase): Promise<T>;
loadBackendTranslation(