Skip to content

Commit 452f85b

Browse files
authored
refactor(core): enforce noImplicitAny (#5605)
* Initial work Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix errors Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Remove .d.ts files Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
1 parent e66e045 commit 452f85b

19 files changed

Lines changed: 365 additions & 199 deletions

File tree

packages/docusaurus/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@
3232
},
3333
"devDependencies": {
3434
"@docusaurus/module-type-aliases": "2.0.0-beta.6",
35+
"@types/copy-webpack-plugin": "^8.0.1",
36+
"@types/css-minimizer-webpack-plugin": "^3.0.2",
3537
"@types/detect-port": "^1.3.0",
38+
"@types/mini-css-extract-plugin": "^2.3.0",
39+
"@types/module-alias": "^2.0.1",
3640
"@types/nprogress": "^0.2.0",
41+
"@types/react-dom": "^17.0.9",
42+
"@types/rtl-detect": "^1.0.0",
43+
"@types/serve-handler": "^6.1.1",
44+
"@types/terser-webpack-plugin": "^5.2.0",
45+
"@types/webpack-bundle-analyzer": "^4.4.1",
3746
"tmp-promise": "^3.0.2"
3847
},
3948
"dependencies": {

packages/docusaurus/src/client/baseUrlIssueBanner/BaseUrlIssueBanner.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ function BaseUrlIssueBannerEnabled() {
8080
// useLayoutEffect fires before DOMContentLoaded.
8181
// It gives the opportunity to avoid inserting the banner in the first place
8282
useLayoutEffect(() => {
83-
window[InsertBannerWindowAttribute] = false;
83+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
84+
(window as any)[InsertBannerWindowAttribute] = false;
8485
}, []);
8586

8687
return (
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
const template: string;
9+
export default template;

packages/docusaurus/src/commands/deploy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import os from 'os';
1616
import {buildUrl} from './buildRemoteBranchUrl';
1717

1818
// GIT_PASS env variable should not appear in logs
19-
function obfuscateGitPass(str) {
19+
function obfuscateGitPass(str: string) {
2020
const gitPass = process.env.GIT_PASS;
2121
return gitPass ? str.replace(gitPass, 'GIT_PASS') : str;
2222
}
2323

2424
// Log executed commands so that user can figure out mistakes on his own
2525
// for example: https://github.com/facebook/docusaurus/issues/3875
26-
function shellExecLog(cmd) {
26+
function shellExecLog(cmd: string) {
2727
try {
2828
const result = shell.exec(cmd);
2929
console.log(
@@ -162,7 +162,7 @@ Try using DEPLOYMENT_BRANCH=main or DEPLOYMENT_BRANCH=master`);
162162
// out to deployment branch.
163163
const currentCommit = shellExecLog('git rev-parse HEAD').stdout.trim();
164164

165-
const runDeploy = async (outputDirectory) => {
165+
const runDeploy = async (outputDirectory: string) => {
166166
const fromPath = outputDirectory;
167167
const toPath = await fs.mkdtemp(
168168
path.join(os.tmpdir(), `${projectName}-${deploymentBranch}`),

packages/docusaurus/src/commands/start.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,22 @@ export default async function start(
8888
}, 500);
8989
const {siteConfig, plugins = []} = props;
9090

91-
const normalizeToSiteDir = (filepath) => {
91+
const normalizeToSiteDir = (filepath: string) => {
9292
if (filepath && path.isAbsolute(filepath)) {
9393
return posixPath(path.relative(siteDir, filepath));
9494
}
9595
return posixPath(filepath);
9696
};
9797

98-
const pluginPaths: string[] = ([] as string[])
98+
const pluginPaths = ([] as string[])
9999
.concat(
100100
...plugins
101101
.map((plugin) => plugin.getPathsToWatch?.() ?? [])
102102
.filter(Boolean),
103103
)
104104
.map(normalizeToSiteDir);
105105

106-
const pathsToWatch: string[] = [
106+
const pathsToWatch = [
107107
...pluginPaths,
108108
props.siteConfigPath,
109109
getTranslationsLocaleDirPath({

packages/docusaurus/src/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function createMDXFallbackPlugin({siteDir}: {siteDir: string}): LoadedPlugin {
224224
loader: require.resolve('@docusaurus/mdx-loader'),
225225
options: {
226226
staticDir: path.join(siteDir, STATIC_DIR_NAME),
227-
isMDXPartial: (_filename) => true, // External mdx files are always meant to be imported as partials
227+
isMDXPartial: (_filename: string) => true, // External mdx files are always meant to be imported as partials
228228
isMDXPartialFrontMatterWarningDisabled: true, // External mdx files might have frontmatter, let's just disable the warning
229229
remarkPlugins: [admonitions],
230230
},

packages/docusaurus/src/server/plugins/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export async function loadPlugins({
123123
// 3. Plugin Lifecycle - contentLoaded.
124124
const pluginsRouteConfigs: RouteConfig[] = [];
125125

126-
const globalData = {};
126+
const globalData: Record<string, Record<string, unknown>> = {};
127127

128128
await Promise.all(
129129
contentLoadedTranslatedPlugins.map(

packages/docusaurus/src/server/routes.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import {
2121
ChunkNames,
2222
} from '@docusaurus/types';
2323

24+
type RegistryMap = {
25+
[chunkName: string]: ChunkRegistry;
26+
};
27+
2428
function indent(str: string) {
2529
const spaces = ' ';
2630
return `${spaces}${str.replace(/(\n)/g, `\n${spaces}`)}`;
@@ -183,15 +187,38 @@ ${indent(NotFoundRouteCode)}
183187
};
184188
}
185189

190+
function genRouteChunkNames(
191+
registry: RegistryMap,
192+
value: Module,
193+
prefix?: string,
194+
name?: string,
195+
): string;
196+
function genRouteChunkNames(
197+
registry: RegistryMap,
198+
value: RouteModule,
199+
prefix?: string,
200+
name?: string,
201+
): ChunkNames;
202+
function genRouteChunkNames(
203+
registry: RegistryMap,
204+
value: RouteModule[],
205+
prefix?: string,
206+
name?: string,
207+
): ChunkNames[];
208+
function genRouteChunkNames(
209+
registry: RegistryMap,
210+
value: RouteModule | RouteModule[] | Module,
211+
prefix?: string,
212+
name?: string,
213+
): ChunkNames | ChunkNames[] | string;
214+
186215
function genRouteChunkNames(
187216
// TODO instead of passing a mutating the registry, return a registry slice?
188-
registry: {
189-
[chunkName: string]: ChunkRegistry;
190-
},
217+
registry: RegistryMap,
191218
value: RouteModule | RouteModule[] | Module | null | undefined,
192219
prefix?: string,
193220
name?: string,
194-
) {
221+
): null | string | ChunkNames | ChunkNames[] {
195222
if (!value) {
196223
return null;
197224
}

packages/docusaurus/src/server/translations/translations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export async function readTranslationFileContent(
5555
const content = JSON.parse(await fs.readFile(filePath, 'utf8'));
5656
ensureTranslationFileContent(content);
5757
return content;
58-
} catch (e) {
58+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59+
} catch (e: any) {
5960
throw new Error(`Invalid translation file at ${filePath}.\n${e.message}`);
6061
}
6162
}

packages/docusaurus/src/server/translations/translationsExtractor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ export async function extractSourceCodeFileTranslations(
157157
}) as Node;
158158

159159
return await extractSourceCodeAstTranslations(ast, sourceCodeFilePath);
160-
} catch (e) {
160+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
161+
} catch (e: any) {
161162
e.message = `Error while attempting to extract Docusaurus translations from source code file at path=${sourceCodeFilePath}\n${e.message}`;
162163
throw e;
163164
}

0 commit comments

Comments
 (0)