Skip to content

Commit

Permalink
Use module augmentation to define missing types
Browse files Browse the repository at this point in the history
This removes the need for some `@ts-expect-error` comments.
  • Loading branch information
remcohaszing committed Feb 15, 2024
1 parent ebf8926 commit af46ff0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
8 changes: 1 addition & 7 deletions example/create-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@

/* eslint-env browser */

// @ts-expect-error: TS in VS Code doesn’t seem to infer this.
import * as hastscript from 'https://esm.sh/hastscript@8?dev'

/** @type {typeof import('hastscript').h} */
const h = hastscript.h
/** @type {typeof import('hastscript').s} */
const s = hastscript.s
import {h, s} from 'https://esm.sh/hastscript@8?dev'

Check failure on line 9 in example/create-tree.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Cannot find module 'https://esm.sh/hastscript@8?dev' or its corresponding type declarations.

Check failure on line 9 in example/create-tree.js

View workflow job for this annotation

GitHub Actions / node

Cannot find module 'https://esm.sh/hastscript@8?dev' or its corresponding type declarations.

Check failure on line 9 in example/create-tree.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Cannot find module 'https://esm.sh/hastscript@8?dev' or its corresponding type declarations.

Check failure on line 9 in example/create-tree.js

View workflow job for this annotation

GitHub Actions / node

Cannot find module 'https://esm.sh/hastscript@8?dev' or its corresponding type declarations.

export function createTree() {
return h('div', [
Expand Down
15 changes: 9 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ import {renderToStaticMarkup} from 'react-dom/server'
// @ts-expect-error: ESM types are wrong.
const Sval = sval.default

/** @type {{Fragment: Fragment, jsx: Jsx, jsxs: Jsx}} */
// @ts-expect-error: the react types are missing.
const production = {Fragment: prod.Fragment, jsx: prod.jsx, jsxs: prod.jsxs}
const production = /** @type {{Fragment: Fragment, jsx: Jsx, jsxs: Jsx}} */ ({
Fragment: prod.Fragment,

Check failure on line 29 in test/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Property 'Fragment' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.

Check failure on line 29 in test/index.js

View workflow job for this annotation

GitHub Actions / node

Property 'Fragment' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.

Check failure on line 29 in test/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Property 'Fragment' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.

Check failure on line 29 in test/index.js

View workflow job for this annotation

GitHub Actions / node

Property 'Fragment' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.
jsx: prod.jsx,

Check failure on line 30 in test/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Property 'jsx' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.

Check failure on line 30 in test/index.js

View workflow job for this annotation

GitHub Actions / node

Property 'jsx' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.

Check failure on line 30 in test/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Property 'jsx' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.

Check failure on line 30 in test/index.js

View workflow job for this annotation

GitHub Actions / node

Property 'jsx' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.
jsxs: prod.jsxs

Check failure on line 31 in test/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Property 'jsxs' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.

Check failure on line 31 in test/index.js

View workflow job for this annotation

GitHub Actions / node

Property 'jsxs' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.

Check failure on line 31 in test/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Property 'jsxs' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.

Check failure on line 31 in test/index.js

View workflow job for this annotation

GitHub Actions / node

Property 'jsxs' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-runtime")'.
})

/** @type {{Fragment: Fragment, jsxDEV: JsxDev}} */
// @ts-expect-error: the react types are missing.
const development = {Fragment: dev.Fragment, jsxDEV: dev.jsxDEV}
const development = /** @type {{Fragment: Fragment, jsxDEV: JsxDev}} */ ({
Fragment: dev.Fragment,

Check failure on line 35 in test/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Property 'Fragment' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-dev-runtime")'.

Check failure on line 35 in test/index.js

View workflow job for this annotation

GitHub Actions / node

Property 'Fragment' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-dev-runtime")'.

Check failure on line 35 in test/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Property 'Fragment' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-dev-runtime")'.

Check failure on line 35 in test/index.js

View workflow job for this annotation

GitHub Actions / node

Property 'Fragment' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-dev-runtime")'.
jsxDEV: dev.jsxDEV

Check failure on line 36 in test/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Property 'jsxDEV' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-dev-runtime")'.

Check failure on line 36 in test/index.js

View workflow job for this annotation

GitHub Actions / node

Property 'jsxDEV' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-dev-runtime")'.

Check failure on line 36 in test/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Property 'jsxDEV' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-dev-runtime")'.

Check failure on line 36 in test/index.js

View workflow job for this annotation

GitHub Actions / node

Property 'jsxDEV' does not exist on type 'typeof import("/home/runner/work/hast-util-to-jsx-runtime/hast-util-to-jsx-runtime/node_modules/@types/react/jsx-dev-runtime")'.
})

test('core', async function (t) {
await t.test('should expose the public api', async function () {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"target": "es2022"
},
"exclude": ["coverage/", "node_modules/"],
"include": ["**/**.js", "lib/components.d.ts"]
"include": ["**/**.js", "lib/components.d.ts", "types.d.ts"]
}

0 comments on commit af46ff0

Please sign in to comment.