Skip to content

Commit 5d858f5

Browse files
authored
refactor: remove unnecessary undefined & use optional chain (#11192)
1 parent abd04a2 commit 5d858f5

3 files changed

Lines changed: 4 additions & 5 deletions

File tree

  • packages
    • docusaurus-plugin-content-docs/src/sidebars
    • docusaurus-plugin-ideal-image/src/theme/IdealImageLegacy/components
    • docusaurus-theme-common/src/utils

packages/docusaurus-plugin-content-docs/src/sidebars/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ Available document ids are:
480480

481481
export function toDocNavigationLink(
482482
doc: DocMetadataBase,
483-
options?: {sidebarItemLabel?: string | undefined},
483+
options?: {sidebarItemLabel?: string},
484484
): PropNavigationLink {
485485
const {
486486
title,

packages/docusaurus-plugin-ideal-image/src/theme/IdealImageLegacy/components/helpers.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const bytesToSize = (bytes) => {
8686
const detectWebpSupport = () => {
8787
if (ssr) return false;
8888
const elem = document.createElement('canvas');
89-
if (elem.getContext && elem.getContext('2d')) {
89+
if (elem.getContext?.('2d')) {
9090
// was able or not to get WebP representation
9191
return elem.toDataURL('image/webp').indexOf('data:image/webp') === 0;
9292
} else {
@@ -97,8 +97,7 @@ const detectWebpSupport = () => {
9797

9898
export const supportsWebp = detectWebpSupport();
9999

100-
const isWebp = (x) =>
101-
x.format === 'webp' || (x.src && x.src.match(/\.webp($|\?.*)/i));
100+
const isWebp = (x) => x.format === 'webp' || x.src?.match(/\.webp($|\?.*)/i);
102101

103102
// eslint-disable-next-line no-shadow
104103
export const selectSrc = ({srcSet, maxImageWidth, supportsWebp}) => {

packages/docusaurus-theme-common/src/utils/useThemeConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type DocsVersionPersistence = 'localStorage' | 'none';
1515

1616
// TODO improve types, use unions
1717
export type NavbarItem = {
18-
type?: string | undefined;
18+
type?: string;
1919
items?: NavbarItem[];
2020
label?: string;
2121
position?: 'left' | 'right';

0 commit comments

Comments
 (0)