mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-30 10:48:05 +02:00
refactor: fix a few type inconsistencies (#5788)
This commit is contained in:
parent
075234851c
commit
72990726e5
11 changed files with 28 additions and 20 deletions
|
@ -51,9 +51,8 @@ function useWindowSize(): WindowSize {
|
||||||
setWindowSize(getWindowSize());
|
setWindowSize(getWindowSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-expect-error: annoying TS setTimeout typing...
|
const timeout = DevSimulateSSR
|
||||||
const timeout: number | undefined = DevSimulateSSR
|
? window.setTimeout(updateWindowSize, 1000)
|
||||||
? setTimeout(updateWindowSize, 1000)
|
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
window.addEventListener('resize', updateWindowSize);
|
window.addEventListener('resize', updateWindowSize);
|
||||||
|
|
|
@ -778,7 +778,7 @@ declare module '@theme/TagsListByLetter' {
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@theme/TagsListInline' {
|
declare module '@theme/TagsListInline' {
|
||||||
export type Tag = Readonly<{label: string; permalink}>;
|
export type Tag = Readonly<{label: string; permalink: string}>;
|
||||||
export interface Props {
|
export interface Props {
|
||||||
readonly tags: readonly Tag[];
|
readonly tags: readonly Tag[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,7 @@ function CollapsibleBase({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<As
|
<As
|
||||||
// @ts-expect-error: see https://twitter.com/sebastienlorber/status/1412784677795110914
|
// @ts-expect-error: the "too complicated type" is produced from "CollapsibleElementType" being a huge union
|
||||||
ref={collapsibleRef}
|
ref={collapsibleRef}
|
||||||
style={disableSSRStyle ? undefined : getSSRStyle(collapsed)}
|
style={disableSSRStyle ? undefined : getSSRStyle(collapsed)}
|
||||||
onTransitionEnd={(e: React.TransitionEvent) => {
|
onTransitionEnd={(e: React.TransitionEvent) => {
|
||||||
|
|
|
@ -18,7 +18,6 @@ import {
|
||||||
TranslationFile,
|
TranslationFile,
|
||||||
} from '@docusaurus/types';
|
} from '@docusaurus/types';
|
||||||
|
|
||||||
// @ts-expect-error: no typedefs :s
|
|
||||||
import resolvePathnameUnsafe from 'resolve-pathname';
|
import resolvePathnameUnsafe from 'resolve-pathname';
|
||||||
|
|
||||||
import {posixPath as posixPathImport} from './posixPath';
|
import {posixPath as posixPathImport} from './posixPath';
|
||||||
|
|
10
packages/docusaurus-utils/src/types.d.ts
vendored
Normal file
10
packages/docusaurus-utils/src/types.d.ts
vendored
Normal 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 'resolve-pathname' {
|
||||||
|
export default function resolvePathname(to: string, from?: string): string;
|
||||||
|
}
|
|
@ -35,7 +35,7 @@
|
||||||
"@types/copy-webpack-plugin": "^8.0.1",
|
"@types/copy-webpack-plugin": "^8.0.1",
|
||||||
"@types/css-minimizer-webpack-plugin": "^3.0.2",
|
"@types/css-minimizer-webpack-plugin": "^3.0.2",
|
||||||
"@types/detect-port": "^1.3.0",
|
"@types/detect-port": "^1.3.0",
|
||||||
"@types/mini-css-extract-plugin": "^2.3.0",
|
"@types/mini-css-extract-plugin": "^1.4.3",
|
||||||
"@types/module-alias": "^2.0.1",
|
"@types/module-alias": "^2.0.1",
|
||||||
"@types/nprogress": "^0.2.0",
|
"@types/nprogress": "^0.2.0",
|
||||||
"@types/react-dom": "^17.0.9",
|
"@types/react-dom": "^17.0.9",
|
||||||
|
|
|
@ -87,8 +87,7 @@ export default async function choosePort(
|
||||||
host: string,
|
host: string,
|
||||||
defaultPort: number,
|
defaultPort: number,
|
||||||
): Promise<number | null> {
|
): Promise<number | null> {
|
||||||
// @ts-expect-error: bad lib typedef?
|
return detect({port: defaultPort, hostname: host}).then(
|
||||||
return detect(defaultPort, host).then(
|
|
||||||
(port) =>
|
(port) =>
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
if (port === defaultPort) {
|
if (port === defaultPort) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ describe('translate', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('reject when no id or message', () => {
|
test('reject when no id or message', () => {
|
||||||
|
// TODO tests are not resolving type defs correctly
|
||||||
// @ts-expect-error: TS should protect when both id/message are missing
|
// @ts-expect-error: TS should protect when both id/message are missing
|
||||||
expect(() => translate({})).toThrowErrorMatchingInlineSnapshot(
|
expect(() => translate({})).toThrowErrorMatchingInlineSnapshot(
|
||||||
`"Docusaurus translation declarations must have at least a translation id or a default translation message"`,
|
`"Docusaurus translation declarations must have at least a translation id or a default translation message"`,
|
||||||
|
|
4
packages/docusaurus/src/types.d.ts
vendored
4
packages/docusaurus/src/types.d.ts
vendored
|
@ -9,7 +9,9 @@ declare module 'remark-admonitions';
|
||||||
|
|
||||||
declare module 'react-loadable-ssr-addon-v5-slorber';
|
declare module 'react-loadable-ssr-addon-v5-slorber';
|
||||||
|
|
||||||
declare module 'resolve-pathname';
|
declare module 'resolve-pathname' {
|
||||||
|
export default function resolvePathname(to: string, from?: string): string;
|
||||||
|
}
|
||||||
|
|
||||||
declare module '@slorber/static-site-generator-webpack-plugin';
|
declare module '@slorber/static-site-generator-webpack-plugin';
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {
|
||||||
mergeWithCustomize,
|
mergeWithCustomize,
|
||||||
customizeArray,
|
customizeArray,
|
||||||
customizeObject,
|
customizeObject,
|
||||||
CustomizeRule,
|
|
||||||
} from 'webpack-merge';
|
} from 'webpack-merge';
|
||||||
import webpack, {
|
import webpack, {
|
||||||
Configuration,
|
Configuration,
|
||||||
|
@ -224,8 +223,7 @@ export function applyConfigureWebpack(
|
||||||
content,
|
content,
|
||||||
);
|
);
|
||||||
if (res && typeof res === 'object') {
|
if (res && typeof res === 'object') {
|
||||||
// @ts-expect-error: annoying error due to enums: https://github.com/survivejs/webpack-merge/issues/179
|
const customizeRules = mergeStrategy ?? {};
|
||||||
const customizeRules: Record<string, CustomizeRule> = mergeStrategy ?? {};
|
|
||||||
return mergeWithCustomize({
|
return mergeWithCustomize({
|
||||||
customizeArray: customizeArray(customizeRules),
|
customizeArray: customizeArray(customizeRules),
|
||||||
customizeObject: customizeObject(customizeRules),
|
customizeObject: customizeObject(customizeRules),
|
||||||
|
|
14
yarn.lock
14
yarn.lock
|
@ -4280,10 +4280,10 @@
|
||||||
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
|
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
|
||||||
integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==
|
integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==
|
||||||
|
|
||||||
"@types/mini-css-extract-plugin@^2.3.0":
|
"@types/mini-css-extract-plugin@^1.4.3":
|
||||||
version "2.3.0"
|
version "1.4.3"
|
||||||
resolved "https://registry.yarnpkg.com/@types/mini-css-extract-plugin/-/mini-css-extract-plugin-2.3.0.tgz#2637bc09347ffa21b75f91b93dd00ce3d3971872"
|
resolved "https://registry.yarnpkg.com/@types/mini-css-extract-plugin/-/mini-css-extract-plugin-1.4.3.tgz#4907ee3953fecd199fab24ef056dabef51ff19a2"
|
||||||
integrity sha512-DeEkl1HsCDij3P7tfIWhQENVXz4wE17Ew0+5+KRh5HAcFcIZMfQg4HxKwEIqulVALYyv7JKisn4BPu3f7OHPVQ==
|
integrity sha512-jyOSVaF4ie2jUGr1uohqeyDrp7ktRthdFxDKzTgbPZtl0QI5geEopW7UKD/DEfn0XgV1KEq/RnZlUmnrEAWbmg==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/node" "*"
|
"@types/node" "*"
|
||||||
tapable "^2.2.0"
|
tapable "^2.2.0"
|
||||||
|
@ -20371,9 +20371,9 @@ webpack-sources@^3.2.0:
|
||||||
integrity sha512-t6BMVLQ0AkjBOoRTZgqrWm7xbXMBzD+XDq2EZ96+vMfn3qKgsvdXZhbPZ4ElUOpdv4u+iiGe+w3+J75iy/bYGA==
|
integrity sha512-t6BMVLQ0AkjBOoRTZgqrWm7xbXMBzD+XDq2EZ96+vMfn3qKgsvdXZhbPZ4ElUOpdv4u+iiGe+w3+J75iy/bYGA==
|
||||||
|
|
||||||
webpack@^5, webpack@^5.1.0, webpack@^5.37.0, webpack@^5.40.0:
|
webpack@^5, webpack@^5.1.0, webpack@^5.37.0, webpack@^5.40.0:
|
||||||
version "5.54.0"
|
version "5.59.1"
|
||||||
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.54.0.tgz#629f0cd14c7a4340af758a3c7cef25c50670ae4d"
|
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.59.1.tgz#60c77e9aad796252153d4d7ab6b2d4c11f0e548c"
|
||||||
integrity sha512-MAVKJMsIUotOQKzFOmN8ZkmMlj7BOyjDU6t1lomW9dWOme5WTStzGa3HMLdV1KYD1AiFETGsznL4LMSvj4tukw==
|
integrity sha512-I01IQV9K96FlpXX3V0L4nvd7gb0r7thfuu1IfT2P4uOHOA77nKARAKDYGe/tScSHKnffNIyQhLC8kRXzY4KEHQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/eslint-scope" "^3.7.0"
|
"@types/eslint-scope" "^3.7.0"
|
||||||
"@types/estree" "^0.0.50"
|
"@types/estree" "^0.0.50"
|
||||||
|
|
Loading…
Add table
Reference in a new issue