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; authorUrl: string;
lovelace: (localize: LocalizeFunc) => LovelaceConfig; lovelace: (localize: LocalizeFunc) => LovelaceConfig;
entities: (localize: LocalizeFunc) => Entity[]; 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 { interface ProcessedTheme {
keys: { [key: string]: "" }; 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. * 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"; import { directive, NodePart, Part } from "lit-html";
export const dynamicElement = directive( 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)) { if (!(part instanceof NodePart)) {
throw new Error( throw new Error(
"dynamicElementDirective can only be used in content bindings" "dynamicElementDirective can only be used in content bindings"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,9 +21,9 @@ export class Entity {
public state: string; 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; public hass?: any;
@ -39,7 +39,7 @@ export class Entity {
this.attributes = baseAttributes; 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 // eslint-disable-next-line
console.log( console.log(
`Unmocked service for ${this.entityId}: ${domain}/${service}`, `Unmocked service for ${this.entityId}: ${domain}/${service}`,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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