From af46ff003a0a35f5f46ed4b10f84725e053f0051 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Thu, 15 Feb 2024 14:17:39 +0100 Subject: [PATCH] Use module augmentation to define missing types This removes the need for some `@ts-expect-error` comments. --- example/create-tree.js | 8 +------- test/index.js | 15 +++++++++------ tsconfig.json | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/example/create-tree.js b/example/create-tree.js index 5ecd609..9a1e030 100644 --- a/example/create-tree.js +++ b/example/create-tree.js @@ -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' export function createTree() { return h('div', [ diff --git a/test/index.js b/test/index.js index 474a091..a1844bd 100644 --- a/test/index.js +++ b/test/index.js @@ -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, + jsx: prod.jsx, + jsxs: prod.jsxs +}) -/** @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, + jsxDEV: dev.jsxDEV +}) test('core', async function (t) { await t.test('should expose the public api', async function () { diff --git a/tsconfig.json b/tsconfig.json index 33654f7..4617360 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"] }