refactor: improve internal typing (#6507)

* refactor: improve internal typing

* fix

* fix test
This commit is contained in:
Joshua Chen 2022-01-29 22:58:40 +08:00 committed by GitHub
parent 58e07a6796
commit 2553f1fb5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 165 additions and 132 deletions

View file

@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
declare module '@docsearch/react/modal';
declare module '@docsearch/react/style';

View file

@ -4,7 +4,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* eslint-disable @typescript-eslint/ban-ts-comment */
import React, {useState, useRef, useCallback, useMemo} from 'react';
import {createPortal} from 'react-dom';
@ -120,9 +119,7 @@ function DocSearch({
}
return Promise.all([
// @ts-ignore
import('@docsearch/react/modal'),
// @ts-ignore
import('@docsearch/react/style'),
import('./styles.css'),
]).then(([{DocSearchModal: Modal}]) => {
@ -271,8 +268,7 @@ function DocSearch({
function SearchBar(): JSX.Element {
const {siteConfig} = useDocusaurusContext();
// @ts-ignore
return <DocSearch {...siteConfig.themeConfig.algolia} />;
return <DocSearch {...(siteConfig.themeConfig.algolia as DocSearchProps)} />;
}
export default SearchBar;

View file

@ -6,7 +6,6 @@
*/
/* eslint-disable jsx-a11y/no-autofocus */
/* eslint-disable @typescript-eslint/ban-ts-comment */
import React, {useEffect, useState, useReducer, useRef} from 'react';
@ -29,6 +28,7 @@ import {useAllDocsData} from '@docusaurus/plugin-content-docs/client';
import Layout from '@theme/Layout';
import Translate, {translate} from '@docusaurus/Translate';
import styles from './styles.module.css';
import type {ThemeConfig} from '@docusaurus/theme-search-algolia';
// Very simple pluralization: probably good enough for now
function useDocumentsFoundPlural() {
@ -151,14 +151,12 @@ type ResultDispatcher =
function SearchPage(): JSX.Element {
const {
siteConfig: {
themeConfig: {
// @ts-ignore
algolia: {appId, apiKey, indexName, externalUrlRegex},
},
},
siteConfig: {themeConfig},
i18n: {currentLocale},
} = useDocusaurusContext();
const {
algolia: {appId, apiKey, indexName, externalUrlRegex},
} = themeConfig as ThemeConfig;
const documentsFoundPlural = useDocumentsFoundPlural();
const docsSearchVersionsHelpers = useDocsSearchVersionsHelpers();