Skip to content

Commit

Permalink
Fixed ts typings
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Apr 24, 2024
1 parent 9a3e71e commit ac27b8b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
File renamed without changes.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"description": "Make your React.js rendering predictable",
"scripts": {
"test": "tsc && bun test && node ./test/all.mjs",
"format": "prettier **/*.mjs **/*.ts --write",
"formatCheck": "prettier **/*.mjs **/*.ts --check"
"format": "prettier **/*.mjs **/*.mts --write",
"formatCheck": "prettier **/*.mjs **/*.mts --check"
},
"type": "module",
"exports": "./index.mjs",
"types": "./index.d.ts",
"types": "./index.d.mts",
"private": false,
"publishConfig": {
"access": "public"
Expand Down
5 changes: 0 additions & 5 deletions src/assertComponent.d.ts

This file was deleted.

16 changes: 12 additions & 4 deletions src/assertComponent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ function assertComponent(result, expectedElement) {
assertComponentImpl("", result, expectedElement);
}

/**
* @typedef {{
* type: any;
* props: { [propName: string]: any };
* children?: Array<TestInstance | string>;
* }} TestInstance
*/

/**
* @param { string } path
* @param { import('./assertComponent').TestInstance | string } result
* @param { import('./assertComponent').TestInstance | string } expectedElement
* @param { TestInstance | string } result
* @param { TestInstance | string } expectedElement
*/
function assertComponentImpl(path, result, expectedElement) {
const name =
Expand Down Expand Up @@ -164,8 +172,8 @@ function assertAttrValue(name, resultValue, expectedValue) {
}

/**
* @param {import('./assertComponent').TestInstance} result
* @returns {(import('./assertComponent').TestInstance | string)[]}
* @param {TestInstance} result
* @returns {(TestInstance | string)[]}
*/
function getComponentChildren(result) {
// in case of ReactElement get children from props
Expand Down
4 changes: 3 additions & 1 deletion test/example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import TestRenderer from "react-test-renderer";
import { assertComponents, mockComponent } from "../index.mjs";

const { describe, it } = await (async () => {
// @ts-ignore
const module = process.isBun ? "bun:test" : "node:test";
// @ts-ignore
return process.isBun // @ts-ignore
? Promise.resolve({ describe: (_, fn) => fn(), it: test })
: import("node:test");
: import(module);
})();

function SubComponent() {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
// use Node's module resolution algorithm, instead of the legacy TS one
"moduleResolution": "node",
//"moduleResolution": "node",
// interop between ESM and CJS modules. Recommended by TS
"esModuleInterop": true,
// significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS
Expand Down

0 comments on commit ac27b8b

Please sign in to comment.