feat: add type guards for various data types and implement behavioral tests#9
Merged
feat: add type guards for various data types and implement behavioral tests#9
Conversation
… tests - Implemented `isNonEmptyArray`, `isNonEmptyArrayOf`, `isNonEmptyString`, `isNull`, `isNullOrUndefined`, `isNullish`, `isNumber`, `isObject`, `isPlainObject`, `isPromise`, `isRegExp`, `isSet`, `isString`, `isSymbol`, `isThenable`, `isUndefined`, `isValidDate` guards. - Created comprehensive tests for each guard using Vitest, ensuring positive and negative cases are covered. - Introduced helper functions for behavioral contract testing to streamline test case definitions. - Enhanced existing guards with improved type checks and error handling. - Added type tests to validate type narrowing functionality for various guards. - Updated `index.ts` to export new guards and maintain module integrity.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands the library’s type guard surface area and modernizes the project’s build/test tooling to support behavioral runtime tests, type-narrowing checks, and dual ESM/CommonJS package output.
Changes:
- Added/updated guards and extracted shared internal helpers (e.g., callable-property and plain-object helpers).
- Replaced the previous monolithic Jest suite with Vitest-based behavioral contract tests plus separate
test-dtype-narrowing checks. - Switched packaging/build to
tsup, updated exports for ESM/CJS interop, and strengthened CI (matrix Node versions + coverage + package smoke test).
Reviewed changes
Copilot reviewed 57 out of 58 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.type-tests.json | Adds a dedicated TS config for type-narrowing (“type tests”) compilation. |
| test-d/narrowing.types.ts | Adds compile-time narrowing assertions for several guards and guard factories. |
| src/index.ts | Exports isPlainObject from the public entrypoint. |
| src/guards/isValidDate.ts | Refactors guard logic to an explicit isDate early-return before checking getTime(). |
| src/guards/isUndefined.ts | Simplifies undefined check to strict equality. |
| src/guards/isThenable.ts | Refactors thenable detection to reuse a shared callable-property helper. |
| src/guards/isPlainObject.ts | Introduces isPlainObject using shared object helper utilities. |
| src/guards/isObject.ts | Refactors isObject to use shared object helper utilities. |
| src/guards/isNonEmptyArrayOf.ts | Refactors for clearer early returns and adjusts guard parameter typing. |
| src/guards/isNonEmptyArray.ts | Refactors for clearer early returns. |
| src/guards/isDefined.ts | Implements isDefined via isNullish for consistency. |
| src/guards/isArrayOf.ts | Refactors for clearer early returns and adjusts guard parameter typing. |
| src/guards/internal/objectHelpers.ts | Adds shared helpers for “non-array object” and “plain prototype” checks. |
| src/guards/internal/hasCallableProperty.ts | Adds shared helper for checking whether a property resolves to a callable value. |
| src/guards/getEnumValues.ts | Tightens typing around enum value extraction helpers. |
| src/guards/createTypeGuard.ts | Adjusts constructor parameter typing (readonly intersection) without changing behavior. |
| src/guards/createEnumGuard.ts | Refactors enum value candidate checks using existing primitive guards and avoids barrel cycles. |
| src/tests/support/test-helpers.ts | Adds reusable behavioral-contract helpers and shared fixtures for runtime guard tests. |
| src/tests/runtime.test.ts | Adds a single runtime test entrypoint that imports all per-guard test files. |
| src/tests/isValidDate.test.ts | Adds behavioral contract tests for isValidDate. |
| src/tests/isUndefined.test.ts | Adds behavioral contract tests for isUndefined. |
| src/tests/isThenable.test.ts | Adds behavioral contract tests for isThenable, including function-thenable coverage. |
| src/tests/isSymbol.test.ts | Adds behavioral contract tests for isSymbol. |
| src/tests/isString.test.ts | Adds behavioral contract tests for isString. |
| src/tests/isSet.test.ts | Adds behavioral contract tests for isSet. |
| src/tests/isRegExp.test.ts | Adds behavioral contract tests for isRegExp. |
| src/tests/isPromise.test.ts | Adds behavioral contract tests for isPromise. |
| src/tests/isPlainObject.test.ts | Adds behavioral contract tests for isPlainObject. |
| src/tests/isObject.test.ts | Adds behavioral contract tests for isObject. |
| src/tests/isNumber.test.ts | Adds behavioral contract tests for isNumber. |
| src/tests/isNullOrUndefined.test.ts | Adds behavioral contract tests for isNullOrUndefined. |
| src/tests/isNullish.test.ts | Adds behavioral contract tests for isNullish. |
| src/tests/isNull.test.ts | Adds behavioral contract tests for isNull. |
| src/tests/isNonEmptyString.test.ts | Adds behavioral contract tests for isNonEmptyString. |
| src/tests/isNonEmptyArrayOf.test.ts | Adds behavioral contract tests for isNonEmptyArrayOf. |
| src/tests/isNonEmptyArray.test.ts | Adds behavioral contract tests for isNonEmptyArray. |
| src/tests/isNaN.test.ts | Adds behavioral contract tests for isNaN. |
| src/tests/isMap.test.ts | Adds behavioral contract tests for isMap. |
| src/tests/isInteger.test.ts | Adds behavioral contract tests for isInteger. |
| src/tests/isFunction.test.ts | Adds behavioral contract tests for isFunction. |
| src/tests/isFiniteNumber.test.ts | Adds behavioral contract tests for isFiniteNumber. |
| src/tests/isError.test.ts | Adds behavioral contract tests for isError. |
| src/tests/isDefined.test.ts | Adds behavioral contract tests for isDefined. |
| src/tests/isDate.test.ts | Adds behavioral contract tests for isDate. |
| src/tests/isBoolean.test.ts | Adds behavioral contract tests for isBoolean. |
| src/tests/isBigInt.test.ts | Adds behavioral contract tests for isBigInt. |
| src/tests/isArrayOf.test.ts | Adds behavioral contract tests for isArrayOf. |
| src/tests/isArray.test.ts | Adds behavioral contract tests for isArray. |
| src/tests/guards.test.ts | Removes the previous large combined test file (replaced by per-guard tests). |
| src/tests/createTypeGuard.test.ts | Adds behavioral contract and naming tests for createTypeGuard. |
| src/tests/createEnumGuard.test.ts | Adds behavioral contract and naming tests for createEnumGuard. |
| scripts/check-package-interop.mjs | Adds an ESM/CJS interop smoke test against built dist/ artifacts. |
| scripts/check-file-coverage.mjs | Adds a per-file coverage threshold validator based on coverage-summary output. |
| README.md | Updates package name, installation/import examples, guard list, and dev commands. |
| package.json | Migrates build/test tooling (tsup + vitest), updates exports for ESM/CJS, and adds CI-oriented scripts. |
| eslint.config.mjs | Updates flat ESLint config, adds ignores, and relaxes JSDoc rule in tests/type-tests. |
| .github/workflows/ci.yml | Expands CI to node-version matrix and adds typecheck/build/package/coverage steps. |
Comments suppressed due to low confidence (1)
src/guards/isPlainObject.ts:32
isPlainObjectcurrently has the same implementation asisObject(both check for a non-null, non-array object whose prototype isObject.prototypeornull). If both exports are intended to remain public, this duplication is easy to drift over time and it’s unclear to consumers when to use which guard. Consider either (a) making one guard an alias/re-export of the other to keep behavior in sync, or (b) adjusting one guard’s semantics and/or JSDoc to clearly differentiate them.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
isNonEmptyArray,isNonEmptyArrayOf,isNonEmptyString,isNull,isNullOrUndefined,isNullish,isNumber,isObject,isPlainObject,isPromise,isRegExp,isSet,isString,isSymbol,isThenable,isUndefined,isValidDateguards.index.tsto export new guards and maintain module integrity.