Skip to content

Commit

Permalink
Add some improved internal types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 14, 2023
1 parent 8f63c05 commit e1d929e
Show file tree
Hide file tree
Showing 21 changed files with 605 additions and 646 deletions.
6 changes: 4 additions & 2 deletions docs/_asset/editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,13 @@ function Playground() {
* @returns {JSX.Element}
*/
function ErrorFallback(props) {
console.log('fb:', arguments)
/** @type {Error} */
// type-coverage:ignore-next-line
const error = props.error
return (
<div role="alert">
<p>Something went wrong:</p>
<DisplayError error={props.error} />
<DisplayError error={error} />
<button type="button" onClick={props.resetErrorBoundary}>
Try again
</button>
Expand Down
1 change: 1 addition & 0 deletions docs/_component/blog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function BlogEntry(props) {
: [meta.readingTime, meta.readingTime]
: []
).map((d) => Math.ceil(d))
/** @type {string | undefined} */
let timeLabel

if (time.length > 1 && time[0] !== time[1]) {
Expand Down
1 change: 1 addition & 0 deletions docs/_component/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function Layout(props) {
: [meta.readingTime, meta.readingTime]
: []
).map((d) => (d > 15 ? Math.round(d / 5) * 5 : Math.ceil(d)))
/** @type {string | undefined} */
let timeLabel

if (metaTime.length > 1 && metaTime[0] !== metaTime[1]) {
Expand Down
3 changes: 3 additions & 0 deletions docs/_component/nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

/**
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('react').ReactNode} ReactNode
* @typedef {import('./sort.js').Item} Item
*/

Expand Down Expand Up @@ -59,7 +60,9 @@ export function NavItem(props) {
const defaultTitle = apStyleTitleCase(
name.replace(/\/$/, '').split('/').pop()
)
/** @type {ReactNode} */
let description
/** @type {string | undefined} */
let published

if (includeDescription) {
Expand Down
18 changes: 11 additions & 7 deletions docs/_component/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,24 @@ export function sortItems(items, sortString = 'navSortSelf,meta.title') {

while (++index < fields.length) {
const [field, order] = fields[index]
/** @type {unknown} */
let a = dlv(left.data, field)
/** @type {unknown} */
let b = dlv(right.data, field)

if (a && typeof a === 'object' && 'valueOf' in a) a = a.valueOf()
if (b && typeof b === 'object' && 'valueOf' in b) b = b.valueOf()

const score =
typeof a === 'number' || typeof b === 'number'
? a === null || a === undefined
? 1
: b === null || b === undefined
? -1
: a - b
: collator(a, b)
typeof a === 'string' && typeof b === 'string'
? collator(a, b)
: typeof a === 'number' && typeof b === 'number'
? a - b
: a === null || a === undefined
? 1
: b === null || b === undefined
? -1
: 0
const result = order === 'asc' ? score : -score
if (result) return result
}
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"#": "needed `any`s",
"ignoreFiles": [
"packages/mdx/lib/util/resolve-evaluate-options.d.ts",
"packages/mdx/lib/util/resolve-evaluate-options.js"
],
"strict": true
},
"xo": {
Expand Down
6 changes: 0 additions & 6 deletions packages/esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
Expand Down
6 changes: 0 additions & 6 deletions packages/loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
Expand Down
6 changes: 0 additions & 6 deletions packages/mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
Expand Down
6 changes: 0 additions & 6 deletions packages/node-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@
"test-api": "node --conditions development --loader=./test/react-18-node-loader.js test/index.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
Expand Down
6 changes: 0 additions & 6 deletions packages/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
"test-api": "node --conditions development --loader=../../script/jsx-loader.js test/test.jsx",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"overrides": [
{
Expand Down
6 changes: 0 additions & 6 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
"test-api": "node --conditions development --loader=../../script/jsx-loader.js test/test.jsx",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"overrides": [
{
Expand Down
16 changes: 13 additions & 3 deletions packages/register/lib/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ function register(options) {
*/
function mdx(module, path) {
const file = processSync(fs.readFileSync(path))
// To do: type `run`.
/** @type {{default: unknown}} */
const result = runSync(file, runtime)
// Something going weird here w/ `type-coverage`.
// type-coverage:ignore-next-line
module.exports = result.default
module.loaded = true
}
Expand Down Expand Up @@ -82,9 +86,15 @@ function load(filePath, callback) {
)
}

import(filePath).then((module) => {
done(null, module)
}, done)
import(filePath).then(
/**
* @param {unknown} module
*/
function (module) {
done(null, module)
},
done
)

/**
*
Expand Down
6 changes: 0 additions & 6 deletions packages/register/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@
"test-api": "node --conditions development --require ./index.cjs test/index.cjs",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
Expand Down
6 changes: 0 additions & 6 deletions packages/remark-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
Expand Down
6 changes: 0 additions & 6 deletions packages/rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
Expand Down
9 changes: 1 addition & 8 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,12 @@
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
},
"xo": {
"prettier": true,
"rules": {
"n/file-extension-in-import": "off",
"unicorn/prefer-node-protocol": "off",
"unicorn/prefer-string-replace-all": "off"
}
},
"gitHead": "bf7deab69996449cb99c2217dff75e65855eb2c1"
}
}
Loading

1 comment on commit e1d929e

@vercel
Copy link

@vercel vercel bot commented on e1d929e Oct 14, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

mdx – ./

mdx-mdx.vercel.app
mdx-git-main-mdx.vercel.app
v2.mdxjs.com
mdxjs.com

Please sign in to comment.