Typescript: start fixing 'strict' mode errors

merge-requests/1138/head
Alex Gleason 2022-03-23 21:43:36 -05:00
rodzic 8d8307adf2
commit 14ec40ee95
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
6 zmienionych plików z 24 dodań i 13 usunięć

Wyświetl plik

@ -59,7 +59,7 @@ export function fetchInstance() {
return api(getState).get('/api/v1/instance').then(({ data: instance }: { data: Record<string, any> }) => {
dispatch({ type: INSTANCE_FETCH_SUCCESS, instance });
if (needsNodeinfo(instance)) {
dispatch(fetchNodeinfo()); // Pleroma < 2.1 backwards compatibility
dispatch(fetchNodeinfo() as any); // Pleroma < 2.1 backwards compatibility
}
}).catch(error => {
console.error(error);
@ -73,8 +73,10 @@ export function loadInstance() {
return (dispatch: AppDispatch, getState: () => RootState) => {
const host = getHost(getState());
return dispatch(rememberInstance(host)).finally(() => {
return dispatch(fetchInstance());
if (!host) return new Promise(r => r(null));
return dispatch(rememberInstance(host) as any).finally(() => {
return dispatch(fetchInstance() as any);
});
};
}

Wyświetl plik

@ -86,7 +86,7 @@ export const calculateStatus = (
const emojiMap = makeEmojiMap(status.emojis);
return status.merge({
search_index: domParser.parseFromString(searchContent, 'text/html').documentElement.textContent,
search_index: domParser.parseFromString(searchContent, 'text/html').documentElement.textContent || undefined,
contentHtml: stripCompatibilityFeatures(emojify(status.content, emojiMap)),
spoilerHtml: emojify(escapeTextContentForBrowser(spoilerText), emojiMap),
hidden: expandSpoilers ? false : spoilerText.length > 0 || status.sensitive,

Wyświetl plik

@ -1,17 +1,17 @@
import localforage from 'localforage';
interface IKVStore extends LocalForage {
getItemOrError?: (key: string) => Promise<any>,
getItemOrError: (key: string) => Promise<any>,
}
// localForage
// https://localforage.github.io/localForage/#settings-api-config
export const KVStore: IKVStore = localforage.createInstance({
export const KVStore = localforage.createInstance({
name: 'soapbox',
description: 'Soapbox offline data store',
driver: localforage.INDEXEDDB,
storeName: 'keyvaluepairs',
});
}) as IKVStore;
// localForage returns 'null' when a key isn't found.
// In the Redux action flow, we want it to fail harder.

Wyświetl plik

@ -13,7 +13,7 @@ const find = (
configs: ImmutableList<Config>,
group: string,
key: string,
): Config => {
): Config | undefined => {
return configs.find(config =>
config.isSuperset(ImmutableMap({ group, key })),
);

Wyświetl plik

@ -61,19 +61,28 @@ function hslToHex(color: Hsl): string {
}
// Generate accent color from brand color
export const generateAccent = (brandColor: string): string => {
const { h } = rgbToHsl(hexToRgb(brandColor));
export const generateAccent = (brandColor: string): string | null => {
const rgb = hexToRgb(brandColor);
if (!rgb) return null;
const { h } = rgbToHsl(rgb);
return hslToHex({ h: h - 15, s: 86, l: 44 });
};
const parseShades = (obj: Record<string, any>, color: string, shades: Record<string, any>) => {
if (typeof shades === 'string') {
const { r, g, b } = hexToRgb(shades);
const rgb = hexToRgb(shades);
if (!rgb) return obj;
const { r, g, b } = rgb;
return obj[`--color-${color}`] = `${r} ${g} ${b}`;
}
return Object.keys(shades).forEach(shade => {
const { r, g, b } = hexToRgb(shades[shade]);
const rgb = hexToRgb(shades[shade]);
if (!rgb) return;
const { r, g, b } = rgb;
obj[`--color-${color}-${shade}`] = `${r} ${g} ${b}`;
});
};

Wyświetl plik

@ -2,7 +2,7 @@
"compilerOptions": {
"baseUrl": "app/",
"sourceMap": true,
"noImplicitAny": true,
"strict": true,
"module": "es6",
"target": "es5",
"jsx": "react",