Comply with noImplicitAny (#9940)

* Stash noImplicitAny work

* Stash

* Fix imports

* Iterate

* Fix tests

* Delint

* Fix tests
This commit is contained in:
Michael Telatynski 2023-02-13 11:39:16 +00:00 committed by GitHub
parent ac7f69216e
commit 61a63e47f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
359 changed files with 1621 additions and 1353 deletions

View file

@ -22,11 +22,11 @@ import SettingsStore from "./settings/SettingsStore";
import ThemeWatcher from "./settings/watchers/ThemeWatcher";
export const DEFAULT_THEME = "light";
const HIGH_CONTRAST_THEMES = {
const HIGH_CONTRAST_THEMES: Record<string, string> = {
light: "light-high-contrast",
};
interface IFontFaces {
interface IFontFaces extends Omit<Record<typeof allowedFontFaceProps[number], string>, "src"> {
src: {
format: string;
url: string;
@ -80,7 +80,7 @@ export function enumerateThemes(): { [key: string]: string } {
"dark": _t("Dark"),
};
const customThemes = SettingsStore.getValue("custom_themes");
const customThemeNames = {};
const customThemeNames: Record<string, string> = {};
for (const { name } of customThemes) {
customThemeNames[`custom-${name}`] = name;
}
@ -126,31 +126,31 @@ const allowedFontFaceProps = [
"font-variation-settings",
"src",
"unicode-range",
];
] as const;
function generateCustomFontFaceCSS(faces: IFontFaces[]): string {
return faces
.map((face) => {
const src =
face.src &&
face.src
.map((srcElement) => {
let format;
if (srcElement.format) {
format = `format("${srcElement.format}")`;
}
if (srcElement.url) {
return `url("${srcElement.url}") ${format}`;
} else if (srcElement.local) {
return `local("${srcElement.local}") ${format}`;
}
return "";
})
.join(", ");
const props = Object.keys(face).filter((prop) => allowedFontFaceProps.includes(prop));
const src = face.src
?.map((srcElement) => {
let format: string;
if (srcElement.format) {
format = `format("${srcElement.format}")`;
}
if (srcElement.url) {
return `url("${srcElement.url}") ${format}`;
} else if (srcElement.local) {
return `local("${srcElement.local}") ${format}`;
}
return "";
})
.join(", ");
const props = Object.keys(face).filter((prop: typeof allowedFontFaceProps[number]) =>
allowedFontFaceProps.includes(prop),
) as Array<typeof allowedFontFaceProps[number]>;
const body = props
.map((prop) => {
let value;
let value: string;
if (prop === "src") {
value = src;
} else if (prop === "font-family") {
@ -169,7 +169,7 @@ function generateCustomFontFaceCSS(faces: IFontFaces[]): string {
function setCustomThemeVars(customTheme: ICustomTheme): void {
const { style } = document.body;
function setCSSColorVariable(name, hexColor, doPct = true): void {
function setCSSColorVariable(name: string, hexColor: string, doPct = true): void {
style.setProperty(`--${name}`, hexColor);
if (doPct) {
// uses #rrggbbaa to define the color with alpha values at 0%, 15% and 50%
@ -215,9 +215,9 @@ export function getCustomTheme(themeName: string): ICustomTheme {
if (!customThemes) {
throw new Error(`No custom themes set, can't set custom theme "${themeName}"`);
}
const customTheme = customThemes.find((t) => t.name === themeName);
const customTheme = customThemes.find((t: ITheme) => t.name === themeName);
if (!customTheme) {
const knownNames = customThemes.map((t) => t.name).join(", ");
const knownNames = customThemes.map((t: ITheme) => t.name).join(", ");
throw new Error(`Can't find custom theme "${themeName}", only know ${knownNames}`);
}
return customTheme;
@ -248,7 +248,7 @@ export async function setTheme(theme?: string): Promise<void> {
const styleElements = new Map<string, HTMLLinkElement>();
const themes = Array.from(document.querySelectorAll<HTMLLinkElement>("[data-mx-theme]"));
themes.forEach((theme) => {
styleElements.set(theme.attributes["data-mx-theme"].value.toLowerCase(), theme);
styleElements.set(theme.dataset.mxTheme.toLowerCase(), theme);
});
if (!styleElements.has(stylesheetName)) {