refactor: fix a lot of errors in type-aware linting (#7477)

This commit is contained in:
Joshua Chen 2022-05-24 15:40:26 +08:00 committed by GitHub
parent 222bf3c091
commit bf1513a3e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
120 changed files with 407 additions and 364 deletions

View file

@ -27,7 +27,7 @@ export function useCollapsible({
initialState,
}: {
/** The initial state. Will be non-collapsed by default. */
initialState: boolean | (() => boolean);
initialState?: boolean | (() => boolean);
}): {
collapsed: boolean;
setCollapsed: Dispatch<SetStateAction<boolean>>;

View file

@ -40,7 +40,7 @@ export function useSkipToContent(): {
e.preventDefault();
const targetElement: HTMLElement | null =
document.querySelector('main:first-of-type') ||
document.querySelector('main:first-of-type') ??
document.querySelector(`.${ThemeClassNames.wrapper.main}`);
if (targetElement) {

View file

@ -38,15 +38,12 @@ function getAnchors({
}: {
minHeadingLevel: number;
maxHeadingLevel: number;
}) {
}): HTMLElement[] {
const selectors = [];
for (let i = minHeadingLevel; i <= maxHeadingLevel; i += 1) {
selectors.push(`h${i}.anchor`);
}
return Array.from(
document.querySelectorAll(selectors.join()),
) as HTMLElement[];
return Array.from(document.querySelectorAll(selectors.join()));
}
function getActiveAnchor(

View file

@ -171,7 +171,7 @@ export function parseLines(
const metastringRangeClassName = magicComments[0]!.className;
const lines = rangeParser(linesRange)
.filter((n) => n > 0)
.map((n) => [n - 1, [metastringRangeClassName]]);
.map((n) => [n - 1, [metastringRangeClassName]] as [number, string[]]);
return {lineClassNames: Object.fromEntries(lines), code};
}
if (language === undefined) {
@ -189,7 +189,7 @@ export function parseLines(
const lineToClassName: {[comment: string]: string} = Object.fromEntries(
magicComments
.filter((d) => d.line)
.map(({className, line}) => [line, className]),
.map(({className, line}) => [line!, className] as [string, string]),
);
const blockStartToClassName: {[comment: string]: string} = Object.fromEntries(
magicComments

View file

@ -70,7 +70,7 @@ export class ReactContextError extends Error {
this.name = 'ReactContextError';
this.message = `Hook ${
this.stack?.split('\n')[1]?.match(/at (?:\w+\.)?(?<name>\w+)/)?.groups!
.name
.name ?? ''
} is called outside the <${providerName}>. ${additionalInfo || ''}`;
}
}

View file

@ -18,7 +18,7 @@ export function isSamePath(
path2: string | undefined,
): boolean {
const normalize = (pathname: string | undefined) =>
(!pathname || pathname?.endsWith('/')
(!pathname || pathname.endsWith('/')
? pathname
: `${pathname}/`
)?.toLowerCase();

View file

@ -112,11 +112,7 @@ export function useScrollPosition(
return;
}
const currentPosition = getScrollPosition()!;
if (dynamicEffect) {
dynamicEffect(currentPosition, lastPositionRef.current);
}
dynamicEffect(currentPosition, lastPositionRef.current);
lastPositionRef.current = currentPosition;
};

View file

@ -39,7 +39,7 @@ export function useContextualSearchFilters(): {locale: string; tags: string[]} {
// plugin instances.
function getDocPluginTags(pluginId: string) {
const activeVersion =
activePluginAndVersion?.activePlugin?.pluginId === pluginId
activePluginAndVersion?.activePlugin.pluginId === pluginId
? activePluginAndVersion.activeVersion
: undefined;

View file

@ -27,7 +27,7 @@ function treeifyTOC(flatTOC: readonly TOCItem[]): TOCTreeNode[] {
// level <i>. We will modify these indices as we iterate through all headings.
// e.g. if an ### H3 was last seen at index 2, then prevIndexForLevel[3] === 2
// indices 0 and 1 will remain unused.
const prevIndexForLevel = Array(7).fill(-1);
const prevIndexForLevel = Array<number>(7).fill(-1);
headings.forEach((curr, currIndex) => {
// Take the last seen index for each ancestor level. the highest index will

View file

@ -95,7 +95,11 @@ function selectPluralMessage(
}
if (parts.length > localePluralForms.pluralForms.length) {
console.error(
`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length}: ${pluralMessages}`,
`For locale=${localePluralForms.locale}, a maximum of ${
localePluralForms.pluralForms.length
} plural forms are expected (${localePluralForms.pluralForms.join(
',',
)}), but the message contains ${parts.length}: ${pluralMessages}`,
);
}
const pluralForm = localePluralForms.select(count);