Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fix a few type inconsistencies #5788

Merged
merged 4 commits into from Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -51,9 +51,8 @@ function useWindowSize(): WindowSize {
setWindowSize(getWindowSize());
}

// @ts-expect-error: annoying TS setTimeout typing...
const timeout: number | undefined = DevSimulateSSR
? setTimeout(updateWindowSize, 1000)
const timeout = DevSimulateSSR
? window.setTimeout(updateWindowSize, 1000)
: undefined;

window.addEventListener('resize', updateWindowSize);
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-theme-classic/src/types.d.ts
Expand Up @@ -778,7 +778,7 @@ declare module '@theme/TagsListByLetter' {
}

declare module '@theme/TagsListInline' {
export type Tag = Readonly<{label: string; permalink}>;
export type Tag = Readonly<{label: string; permalink: string}>;
export interface Props {
readonly tags: readonly Tag[];
}
Expand Down
Expand Up @@ -189,7 +189,7 @@ function CollapsibleBase({

return (
<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}
style={disableSSRStyle ? undefined : getSSRStyle(collapsed)}
onTransitionEnd={(e: React.TransitionEvent) => {
Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus-utils/src/index.ts
Expand Up @@ -18,7 +18,6 @@ import {
TranslationFile,
} from '@docusaurus/types';

// @ts-expect-error: no typedefs :s
import resolvePathnameUnsafe from 'resolve-pathname';

import {posixPath as posixPathImport} from './posixPath';
Expand Down
10 changes: 10 additions & 0 deletions packages/docusaurus-utils/src/types.d.ts
@@ -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;
}
2 changes: 1 addition & 1 deletion packages/docusaurus/package.json
Expand Up @@ -35,7 +35,7 @@
"@types/copy-webpack-plugin": "^8.0.1",
"@types/css-minimizer-webpack-plugin": "^3.0.2",
"@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/nprogress": "^0.2.0",
"@types/react-dom": "^17.0.9",
Expand Down
3 changes: 1 addition & 2 deletions packages/docusaurus/src/choosePort.ts
Expand Up @@ -87,8 +87,7 @@ export default async function choosePort(
host: string,
defaultPort: number,
): Promise<number | null> {
// @ts-expect-error: bad lib typedef?
return detect(defaultPort, host).then(
return detect({port: defaultPort, hostname: host}).then(
(port) =>
new Promise((resolve) => {
if (port === defaultPort) {
Expand Down
Expand Up @@ -23,6 +23,7 @@ describe('translate', () => {
});

test('reject when no id or message', () => {
// TODO tests are not resolving type defs correctly
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, noticed that too, but can't understand why 😓 my union type works in TS playground though...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not picking up any type at all (the types are any), because they are coming down from the .d.ts files, I guess?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, but for sure we don't use TS well on tests, there are many places with type errors that are not reported by CI (I guess it was something temporary, but in the end the CI should also check tests with tsc).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, right now tsc ignores test files. We should typecheck these with a separate workflow with --noEmit, maybe after #5612 :P (Going to spend a while playing with the TS API)

// @ts-expect-error: TS should protect when both id/message are missing
expect(() => translate({})).toThrowErrorMatchingInlineSnapshot(
`"Docusaurus translation declarations must have at least a translation id or a default translation message"`,
Expand Down
4 changes: 3 additions & 1 deletion packages/docusaurus/src/types.d.ts
Expand Up @@ -9,7 +9,9 @@ declare module 'remark-admonitions';

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';

Expand Down
4 changes: 1 addition & 3 deletions packages/docusaurus/src/webpack/utils.ts
Expand Up @@ -10,7 +10,6 @@ import {
mergeWithCustomize,
customizeArray,
customizeObject,
CustomizeRule,
} from 'webpack-merge';
import webpack, {
Configuration,
Expand Down Expand Up @@ -224,8 +223,7 @@ export function applyConfigureWebpack(
content,
);
if (res && typeof res === 'object') {
// @ts-expect-error: annoying error due to enums: https://github.com/survivejs/webpack-merge/issues/179
const customizeRules: Record<string, CustomizeRule> = mergeStrategy ?? {};
const customizeRules = mergeStrategy ?? {};
return mergeWithCustomize({
customizeArray: customizeArray(customizeRules),
customizeObject: customizeObject(customizeRules),
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Expand Up @@ -4280,10 +4280,10 @@
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==

"@types/mini-css-extract-plugin@^2.3.0":
version "2.3.0"
resolved "https://registry.yarnpkg.com/@types/mini-css-extract-plugin/-/mini-css-extract-plugin-2.3.0.tgz#2637bc09347ffa21b75f91b93dd00ce3d3971872"
integrity sha512-DeEkl1HsCDij3P7tfIWhQENVXz4wE17Ew0+5+KRh5HAcFcIZMfQg4HxKwEIqulVALYyv7JKisn4BPu3f7OHPVQ==
"@types/mini-css-extract-plugin@^1.4.3":
version "1.4.3"
resolved "https://registry.yarnpkg.com/@types/mini-css-extract-plugin/-/mini-css-extract-plugin-1.4.3.tgz#4907ee3953fecd199fab24ef056dabef51ff19a2"
integrity sha512-jyOSVaF4ie2jUGr1uohqeyDrp7ktRthdFxDKzTgbPZtl0QI5geEopW7UKD/DEfn0XgV1KEq/RnZlUmnrEAWbmg==
dependencies:
"@types/node" "*"
tapable "^2.2.0"
Expand Down Expand Up @@ -20371,9 +20371,9 @@ webpack-sources@^3.2.0:
integrity sha512-t6BMVLQ0AkjBOoRTZgqrWm7xbXMBzD+XDq2EZ96+vMfn3qKgsvdXZhbPZ4ElUOpdv4u+iiGe+w3+J75iy/bYGA==

webpack@^5, webpack@^5.1.0, webpack@^5.37.0, webpack@^5.40.0:
version "5.54.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.54.0.tgz#629f0cd14c7a4340af758a3c7cef25c50670ae4d"
integrity sha512-MAVKJMsIUotOQKzFOmN8ZkmMlj7BOyjDU6t1lomW9dWOme5WTStzGa3HMLdV1KYD1AiFETGsznL4LMSvj4tukw==
version "5.59.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.59.1.tgz#60c77e9aad796252153d4d7ab6b2d4c11f0e548c"
integrity sha512-I01IQV9K96FlpXX3V0L4nvd7gb0r7thfuu1IfT2P4uOHOA77nKARAKDYGe/tScSHKnffNIyQhLC8kRXzY4KEHQ==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.50"
Expand Down