mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-24 20:17:50 +02:00
refactor: enable a few TS flags (#6852)
* refactor: enable a few TS flags * refactor * revert to working version * fix * better * change
This commit is contained in:
parent
9f925a42bf
commit
4db0c620de
71 changed files with 210 additions and 174 deletions
|
@ -58,7 +58,7 @@ export default function Details({
|
|||
data-collapsed={collapsed}
|
||||
className={clsx(
|
||||
styles.details,
|
||||
{[styles.isBrowser]: isBrowser},
|
||||
{[styles.isBrowser!]: isBrowser},
|
||||
props.className,
|
||||
)}
|
||||
onMouseDown={(e) => {
|
||||
|
|
|
@ -115,7 +115,7 @@ export function parseLines(
|
|||
// Highlighted lines specified in props: don't parse the content
|
||||
if (metastring && highlightLinesRangeRegex.test(metastring)) {
|
||||
const highlightLinesRange = metastring.match(highlightLinesRangeRegex)!
|
||||
.groups!.range;
|
||||
.groups!.range!;
|
||||
const highlightLines = rangeParser(highlightLinesRange)
|
||||
.filter((n) => n > 0)
|
||||
.map((n) => n - 1);
|
||||
|
@ -131,7 +131,7 @@ export function parseLines(
|
|||
let highlightRange = '';
|
||||
// loop through lines
|
||||
for (let lineNumber = 0; lineNumber < lines.length; ) {
|
||||
const line = lines[lineNumber];
|
||||
const line = lines[lineNumber]!;
|
||||
const match = line.match(directiveRegex);
|
||||
if (match !== null) {
|
||||
const directive = match.slice(1).find((item) => item !== undefined);
|
||||
|
|
|
@ -71,7 +71,7 @@ function readStorageState({
|
|||
pluginId,
|
||||
versionPersistence,
|
||||
);
|
||||
const pluginData = allDocsData[pluginId];
|
||||
const pluginData = allDocsData[pluginId]!;
|
||||
const versionExists = pluginData.versions.some(
|
||||
(version) => version.name === preferredVersionNameUnsafe,
|
||||
);
|
||||
|
|
|
@ -25,7 +25,7 @@ export function useDocsPreferredVersion(
|
|||
const docsData = useDocsData(pluginId);
|
||||
const [state, api] = useDocsPreferredVersionContext();
|
||||
|
||||
const {preferredVersionName} = state[pluginId];
|
||||
const {preferredVersionName} = state[pluginId]!;
|
||||
|
||||
const preferredVersion = preferredVersionName
|
||||
? docsData.versions.find((version) => version.name === preferredVersionName)
|
||||
|
@ -49,8 +49,8 @@ export function useDocsPreferredVersionByPluginId(): Record<
|
|||
const [state] = useDocsPreferredVersionContext();
|
||||
|
||||
function getPluginIdPreferredVersion(pluginId: string) {
|
||||
const docsData = allDocsData[pluginId];
|
||||
const {preferredVersionName} = state[pluginId];
|
||||
const docsData = allDocsData[pluginId]!;
|
||||
const {preferredVersionName} = state[pluginId]!;
|
||||
|
||||
return preferredVersionName
|
||||
? docsData.versions.find(
|
||||
|
|
|
@ -19,7 +19,7 @@ type TagsListItem = Readonly<{name: string; permalink: string; count: number}>;
|
|||
export type TagLetterEntry = Readonly<{letter: string; tags: TagsListItem[]}>;
|
||||
|
||||
function getTagLetter(tag: string): string {
|
||||
return tag[0].toUpperCase();
|
||||
return tag[0]!.toUpperCase();
|
||||
}
|
||||
|
||||
export function listTagsByLetters(
|
||||
|
@ -29,8 +29,8 @@ export function listTagsByLetters(
|
|||
const groups: Record<string, TagsListItem[]> = {};
|
||||
Object.values(tags).forEach((tag) => {
|
||||
const letter = getTagLetter(tag.name);
|
||||
groups[letter] = groups[letter] ?? [];
|
||||
groups[letter].push(tag);
|
||||
groups[letter] ??= [];
|
||||
groups[letter]!.push(tag);
|
||||
});
|
||||
|
||||
return (
|
||||
|
|
|
@ -44,7 +44,7 @@ function treeifyTOC(flatTOC: readonly TOCItem[]): TOCTreeNode[] {
|
|||
headings.forEach((heading) => {
|
||||
const {parentIndex, ...rest} = heading;
|
||||
if (parentIndex >= 0) {
|
||||
headings[parentIndex].children.push(rest);
|
||||
headings[parentIndex]!.children.push(rest);
|
||||
} else {
|
||||
rootNodes.push(rest);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,9 @@ export function useContextualSearchFilters(): useContextualSearchFiltersReturns
|
|||
|
||||
const preferredVersion = docsPreferredVersionByPluginId[pluginId];
|
||||
|
||||
const latestVersion = allDocsData[pluginId].versions.find((v) => v.isLast)!;
|
||||
const latestVersion = allDocsData[pluginId]!.versions.find(
|
||||
(v) => v.isLast,
|
||||
)!;
|
||||
|
||||
const version = activeVersion ?? preferredVersion ?? latestVersion;
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ function selectPluralMessage(
|
|||
const parts = pluralMessages.split(separator);
|
||||
|
||||
if (parts.length === 1) {
|
||||
return parts[0];
|
||||
return parts[0]!;
|
||||
}
|
||||
if (parts.length > localePluralForms.pluralForms.length) {
|
||||
console.error(
|
||||
|
@ -110,7 +110,7 @@ function selectPluralMessage(
|
|||
const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
|
||||
// In case of not enough plural form messages, we take the last one (other)
|
||||
// instead of returning undefined
|
||||
return parts[Math.min(pluralFormIndex, parts.length - 1)];
|
||||
return parts[Math.min(pluralFormIndex, parts.length - 1)]!;
|
||||
}
|
||||
|
||||
export function usePluralForm(): {
|
||||
|
|
|
@ -83,7 +83,7 @@ function getActiveAnchor(
|
|||
}
|
||||
// no anchor under viewport top? (ie we are at the bottom of the page)
|
||||
// => highlight the last anchor found
|
||||
return anchors[anchors.length - 1];
|
||||
return anchors[anchors.length - 1] ?? null;
|
||||
}
|
||||
|
||||
function getLinkAnchorValue(link: HTMLAnchorElement): string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue