Skip to content

Commit

Permalink
Clean up some unnecessary any
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Nov 7, 2022
1 parent 85d32d2 commit ab51894
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/lib/converter/comments/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const wantedKinds: Record<ReflectionKind, ts.SyntaxKind[]> = {
ts.SyntaxKind.PropertySignature,
ts.SyntaxKind.BinaryExpression,
ts.SyntaxKind.PropertyAssignment,
// class X { constructor(/** Comment */ readonly z: any) }
// class X { constructor(/** Comment */ readonly z: string) }
ts.SyntaxKind.Parameter,
],
[ReflectionKind.Method]: [
Expand Down
32 changes: 32 additions & 0 deletions src/lib/converter/plugins/CommentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const NEVER_RENDERED = [
/**
* Handles most behavior triggered by comments. `@group` and `@category` are handled by their respective plugins, but everything else is here.
*
* How it works today
* ==================
* During conversion:
* - Handle visibility flags (`@private`, `@protected`. `@public`)
* - Handle module renames (`@module`)
Expand All @@ -68,6 +70,36 @@ const NEVER_RENDERED = [
* - Copy auto inherited comments from heritage clauses
* - Handle `@inheritDoc`
* - Resolve `@link` tags to point to target reflections
*
* How it should work
* ==================
* During conversion:
* - Handle visibility flags (`@private`, `@protected`. `@public`)
* - Handle module renames (`@module`)
* - Remove excluded tags & comment discovery tags (`@module`, `@packageDocumentation`)
*
* Resolve begin (100):
* - Copy auto inherited comments from heritage clauses
* - Apply `@label` tag
*
* Resolve begin (75)
* - Handle `@inheritDoc`
*
* Resolve begin (50)
* - Copy comments on signature containers to the signature if signatures don't already have a comment
* and then remove the comment on the container.
* - Copy comments for type parameters from the parent container (for classes/interfaces)
*
* Resolve begin (25)
* - Remove hidden reflections
*
* Resolve:
* - Copy comments to parameters and type parameters (for signatures)
* - Apply `@group` and `@category` tags
*
* Resolve end:
* - Resolve `@link` tags to point to target reflections
*
*/
@Component({ name: "comment" })
export class CommentPlugin extends ConverterComponent {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ export class OptionalType extends Type {
* Represents a type predicate.
*
* ```ts
* function isString(anything: any): anything is string {}
* function isString(x: unknown): x is string {}
* function assert(condition: boolean): asserts condition {}
* ```
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/output/themes/MarkedPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ output file :
) ?? {}) as Marked.marked.MarkedOptions;

// Set some default values if they are not specified via the TypeDoc option
markedOptions.highlight ??= (text: any, lang: any) =>
markedOptions.highlight ??= (text, lang) =>
this.getHighlighted(text, lang);
markedOptions.renderer ??= customMarkedRenderer;
markedOptions.mangle ??= false; // See https://github.com/TypeStrong/typedoc/issues/1395
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const debounce = (fn: Function, wait: number = 100) => {
export const debounce = (fn: () => void, wait: number = 100) => {
let timeout: ReturnType<typeof setTimeout>;
return (...args: any[]) => {
return () => {
clearTimeout(timeout);
timeout = setTimeout(() => fn(args), wait);
timeout = setTimeout(() => fn(), wait);
};
};
18 changes: 6 additions & 12 deletions src/lib/utils/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Path from "path";
import type { Application } from "../application";
import type { Logger } from "./loggers";
import { nicePath } from "./paths";
import { validate } from "./validation";

export function loadPlugins(app: Application, plugins: readonly string[]) {
if (plugins.includes("none")) {
Expand Down Expand Up @@ -97,7 +98,7 @@ export function discoverPlugins(app: Application): string[] {
/**
* Load and parse the given `package.json`.
*/
function loadPackageInfo(logger: Logger, fileName: string): any {
function loadPackageInfo(logger: Logger, fileName: string): unknown {
try {
return require(fileName);
} catch {
Expand All @@ -111,20 +112,13 @@ const PLUGIN_KEYWORDS = ["typedocplugin", "typedoc-plugin", "typedoc-theme"];
/**
* Test whether the given package info describes a TypeDoc plugin.
*/
function isPlugin(info: any): boolean {
if (typeof info !== "object" || !info) {
function isPlugin(info: unknown): boolean {
if (!validate({ keywords: [Array, String] }, info)) {
return false;
}

const keywords: unknown[] = info.keywords;
if (!keywords || !Array.isArray(keywords)) {
return false;
}

return keywords.some(
(keyword) =>
typeof keyword === "string" &&
PLUGIN_KEYWORDS.includes(keyword.toLocaleLowerCase())
return info.keywords.some((keyword) =>
PLUGIN_KEYWORDS.includes(keyword.toLocaleLowerCase())
);
}

Expand Down

0 comments on commit ab51894

Please sign in to comment.