Skip to content

Commit 2572b18

Browse files
committed
fix a bunch of type errors by adding type declarations, suppress ~600 errors with noImplicitAny disabled, which we'll fix later
1 parent c860c65 commit 2572b18

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+588
-235
lines changed

docs/plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ By default, the hyperlink on the current page is recognized and the content is s
2525
insertBefore: '.sidebar-nav', // CSS selector in .sidebar scope
2626
2727
maxAge: 86400000, // Expiration time, the default one day
28-
paths: [], // or 'auto'
28+
paths: [], // string[] of files to search in, or 'auto' for discovery based on your sidebar
2929
placeholder: 'Type to search',
3030
3131
// Localization

package-lock.json

Lines changed: 21 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
"@rollup/plugin-node-resolve": "^16.0.0",
5252
"@rollup/plugin-replace": "^6.0.1",
5353
"@rollup/plugin-terser": "^0.4.3",
54+
"@types/common-tags": "^1.8.4",
5455
"@types/eslint": "^8.40.2",
56+
"@types/prismjs": "^1.26.5",
5557
"axios": "^1.5.0",
5658
"browser-sync": "^3.0.2",
5759
"common-tags": "^1.8.0",
@@ -78,6 +80,7 @@
7880
"rimraf": "^6.1.0",
7981
"rollup": "^4.17.2",
8082
"rollup-plugin-import-css": "^4.0.1",
83+
"typescript": "^5.9.3",
8184
"vue": "^3.4.27",
8285
"xhr-mock": "^2.5.1"
8386
},

src/core/Docsify.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import prism from 'prismjs';
1+
import * as prism from 'prismjs';
22
import { Router } from './router/index.js';
33
import { Render } from './render/index.js';
44
import { Fetch } from './fetch/index.js';
55
import { Events } from './event/index.js';
66
import { VirtualRoutes } from './virtual-routes/index.js';
77

8+
// CONTINUE Prism type
9+
console.log('##### Prism:', prism);
10+
811
import config from './config.js';
912
import { isFn } from './util/core.js';
1013
import { Lifecycle } from './init/lifecycle.js';

src/core/config.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { hyphenate, isPrimitive } from './util/core.js';
33

44
const currentScript = document.currentScript;
55

6+
/** @typedef {any} TODO */
7+
68
/**
79
@typedef {
810
{
@@ -18,6 +20,7 @@ const currentScript = document.currentScript;
1820
externalLinkRel: 'noopener' | string
1921
externalLinkTarget: '_blank' | '_self' | '_parent' | '_top' | '_unfencedTop'
2022
formatUpdated: string
23+
frontMatter: Record<string, TODO>
2124
ga: string
2225
homepage: string
2326
keyBindings: false | {
@@ -129,10 +132,13 @@ export default function (vm, config = {}) {
129132
},
130133
},
131134

132-
typeof window.$docsify === 'function'
133-
? window.$docsify(vm)
134-
: window.$docsify,
135+
// Handle non-function configs no matter what (f.e. plugins assign options onto it)
136+
window.$docsify,
137+
138+
// Also handle function config (the app can specificy a function, and plugins will assign options onto it)
139+
typeof window.$docsify === 'function' ? window.$docsify(vm) : undefined,
135140

141+
// Finally, user config passed directly to the instance has priority.
136142
config,
137143
);
138144

@@ -143,8 +149,10 @@ export default function (vm, config = {}) {
143149
{
144150
toggleSidebar: {
145151
bindings: ['\\'],
146-
callback(e) {
147-
const toggleElm = document.querySelector('.sidebar-toggle-button');
152+
callback(/** @type {KeyboardEvent} */ e) {
153+
const toggleElm = /** @type {HTMLElement} */ (
154+
document.querySelector('.sidebar-toggle-button')
155+
);
148156

149157
if (toggleElm) {
150158
toggleElm.click();
@@ -164,7 +172,9 @@ export default function (vm, config = {}) {
164172
)[0];
165173

166174
if (script) {
167-
for (const prop of Object.keys(config)) {
175+
for (const prop of /** @type {(keyof DocsifyConfig)[]} */ (
176+
Object.keys(config)
177+
)) {
168178
const val = script.getAttribute('data-' + hyphenate(prop));
169179

170180
if (isPrimitive(val)) {
@@ -173,6 +183,8 @@ export default function (vm, config = {}) {
173183
'data-' + hyphenate(prop)
174184
}) are deprecated.`,
175185
);
186+
187+
// @ts-expect-error too dynamic for TS
176188
config[prop] = val === '' ? true : val;
177189
}
178190
}

0 commit comments

Comments
 (0)