mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-30 10:48:05 +02:00
chore(website): enable strict compiler option (#6012)
This commit is contained in:
parent
d25bf24753
commit
3334bfb4fa
10 changed files with 31 additions and 22 deletions
|
@ -45,7 +45,7 @@ const allDocHomesPaths = [
|
||||||
const isDev = process.env.NODE_ENV === 'development';
|
const isDev = process.env.NODE_ENV === 'development';
|
||||||
|
|
||||||
const isDeployPreview =
|
const isDeployPreview =
|
||||||
process.env.NETLIFY && process.env.CONTEXT === 'deploy-preview';
|
!!process.env.NETLIFY && process.env.CONTEXT === 'deploy-preview';
|
||||||
|
|
||||||
// Used to debug production build issues faster
|
// Used to debug production build issues faster
|
||||||
const isBuildFast = !!process.env.BUILD_FAST;
|
const isBuildFast = !!process.env.BUILD_FAST;
|
||||||
|
|
|
@ -38,7 +38,7 @@ const APITableRow = forwardRef(
|
||||||
name,
|
name,
|
||||||
children,
|
children,
|
||||||
}: {name: string | undefined; children: ReactElement<ComponentProps<'tr'>>},
|
}: {name: string | undefined; children: ReactElement<ComponentProps<'tr'>>},
|
||||||
ref: React.RefObject<HTMLTableRowElement>,
|
ref: React.ForwardedRef<HTMLTableRowElement>,
|
||||||
) => {
|
) => {
|
||||||
const entryName = getText(children);
|
const entryName = getText(children);
|
||||||
const id = name ? `${name}-${entryName}` : entryName;
|
const id = name ? `${name}-${entryName}` : entryName;
|
||||||
|
|
|
@ -29,20 +29,20 @@ describe('users', () => {
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const size = imageSize(path.join(imageDir, file));
|
const size = imageSize(path.join(imageDir, file));
|
||||||
|
|
||||||
if (size.width < minCardImageWidth) {
|
if (size.width! < minCardImageWidth) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Image width should be >= ${minCardImageWidth}
|
`Image width should be >= ${minCardImageWidth}
|
||||||
Image=${file}`,
|
Image=${file}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (size.height < minCardImageHeight) {
|
if (size.height! < minCardImageHeight) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Image height should be >= ${minCardImageHeight}
|
`Image height should be >= ${minCardImageHeight}
|
||||||
Image=${file}`,
|
Image=${file}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const scaledHeight = size.height / (size.width / minCardImageWidth);
|
const scaledHeight = size.height! / (size.width! / minCardImageWidth);
|
||||||
if (scaledHeight < minCardImageHeightScaled) {
|
if (scaledHeight < minCardImageHeightScaled) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Image height is too small compared to width
|
`Image height is too small compared to width
|
||||||
|
@ -159,7 +159,9 @@ function ensureUserValid(user: User) {
|
||||||
checkOpenSource();
|
checkOpenSource();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Showcase site with title=${user.title} contains errors:\n${e.message}`,
|
`Showcase site with title=${user.title} contains errors:\n${
|
||||||
|
(e as Error).message
|
||||||
|
}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,13 +82,11 @@ const QUOTES = [
|
||||||
|
|
||||||
function Home(): JSX.Element {
|
function Home(): JSX.Element {
|
||||||
const {
|
const {
|
||||||
siteConfig: {
|
siteConfig: {customFields, tagline},
|
||||||
customFields: {description},
|
|
||||||
tagline,
|
|
||||||
},
|
|
||||||
} = useDocusaurusContext();
|
} = useDocusaurusContext();
|
||||||
|
const {description} = customFields as {description: string};
|
||||||
return (
|
return (
|
||||||
<Layout title={tagline} description={description as string}>
|
<Layout title={tagline} description={description}>
|
||||||
<main>
|
<main>
|
||||||
<div className={styles.hero}>
|
<div className={styles.hero}>
|
||||||
<div className={styles.heroInner}>
|
<div className={styles.heroInner}>
|
||||||
|
|
|
@ -71,13 +71,13 @@ const ShowcaseTagSelect = React.forwardRef<HTMLLabelElement, Props>(
|
||||||
}}
|
}}
|
||||||
onFocus={(e) => {
|
onFocus={(e) => {
|
||||||
if (e.relatedTarget) {
|
if (e.relatedTarget) {
|
||||||
e.target.nextElementSibling.dispatchEvent(
|
e.target.nextElementSibling?.dispatchEvent(
|
||||||
new KeyboardEvent('focus'),
|
new KeyboardEvent('focus'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
e.target.nextElementSibling.dispatchEvent(
|
e.target.nextElementSibling?.dispatchEvent(
|
||||||
new KeyboardEvent('blur'),
|
new KeyboardEvent('blur'),
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -26,10 +26,12 @@ export default function Tooltip({
|
||||||
delay,
|
delay,
|
||||||
}: Props): JSX.Element {
|
}: Props): JSX.Element {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [referenceElement, setReferenceElement] = useState<HTMLElement>(null);
|
const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(
|
||||||
const [popperElement, setPopperElement] = useState<HTMLElement>(null);
|
null,
|
||||||
const [arrowElement, setArrowElement] = useState<HTMLElement>(null);
|
);
|
||||||
const [container, setContainer] = useState<Element>(null);
|
const [popperElement, setPopperElement] = useState<HTMLElement | null>(null);
|
||||||
|
const [arrowElement, setArrowElement] = useState<HTMLElement | null>(null);
|
||||||
|
const [container, setContainer] = useState<Element | null>(null);
|
||||||
const {styles: popperStyles, attributes} = usePopper(
|
const {styles: popperStyles, attributes} = usePopper(
|
||||||
referenceElement,
|
referenceElement,
|
||||||
popperElement,
|
popperElement,
|
||||||
|
@ -51,7 +53,7 @@ export default function Tooltip({
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const timeout = useRef<number>(null);
|
const timeout = useRef<number | null>(null);
|
||||||
const tooltipId = `${id}_tooltip`;
|
const tooltipId = `${id}_tooltip`;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -78,7 +80,7 @@ export default function Tooltip({
|
||||||
|
|
||||||
// Remove the title ahead of time to avoid displaying
|
// Remove the title ahead of time to avoid displaying
|
||||||
// two tooltips at the same time (native + this one).
|
// two tooltips at the same time (native + this one).
|
||||||
referenceElement.removeAttribute('title');
|
referenceElement?.removeAttribute('title');
|
||||||
|
|
||||||
timeout.current = window.setTimeout(() => {
|
timeout.current = window.setTimeout(() => {
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
|
@ -86,7 +88,7 @@ export default function Tooltip({
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
clearInterval(timeout.current);
|
clearInterval(timeout.current!);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ function restoreUserState(userState: UserState | null) {
|
||||||
scrollTopPosition: 0,
|
scrollTopPosition: 0,
|
||||||
focusedElementId: undefined,
|
focusedElementId: undefined,
|
||||||
};
|
};
|
||||||
|
// @ts-expect-error: if focusedElementId is undefined it returns null
|
||||||
document.getElementById(focusedElementId)?.focus();
|
document.getElementById(focusedElementId)?.focus();
|
||||||
window.scrollTo({top: scrollTopPosition});
|
window.scrollTo({top: scrollTopPosition});
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,9 @@ function Version(): JSX.Element {
|
||||||
} = useDocusaurusContext();
|
} = useDocusaurusContext();
|
||||||
const versions = useVersions();
|
const versions = useVersions();
|
||||||
const latestVersion = useLatestVersion();
|
const latestVersion = useLatestVersion();
|
||||||
const currentVersion = versions.find((version) => version.name === 'current');
|
const currentVersion = versions.find(
|
||||||
|
(version) => version.name === 'current',
|
||||||
|
)!;
|
||||||
const pastVersions = versions.filter(
|
const pastVersions = versions.filter(
|
||||||
(version) => version !== latestVersion && version.name !== 'current',
|
(version) => version !== latestVersion && version.name !== 'current',
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,7 +11,10 @@ export function difference<T>(...arrays: T[][]): T[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inspired by https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_sortby-and-_orderby
|
// Inspired by https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_sortby-and-_orderby
|
||||||
export function sortBy<T>(array: T[], getter: (item: T) => unknown): T[] {
|
export function sortBy<T>(
|
||||||
|
array: T[],
|
||||||
|
getter: (item: T) => string | number | boolean,
|
||||||
|
): T[] {
|
||||||
const sortedArray = [...array];
|
const sortedArray = [...array];
|
||||||
sortedArray.sort((a, b) =>
|
sortedArray.sort((a, b) =>
|
||||||
// eslint-disable-next-line no-nested-ternary
|
// eslint-disable-next-line no-nested-ternary
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
"lib": ["DOM", "ESNext"],
|
"lib": ["DOM", "ESNext"],
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
|
"strict": true,
|
||||||
"types": ["@types/jest"]
|
"types": ["@types/jest"]
|
||||||
},
|
},
|
||||||
"exclude": ["src/sw.js"]
|
"exclude": ["src/sw.js"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue