diff --git a/.changeset/lazy-seas-tan.md b/.changeset/lazy-seas-tan.md new file mode 100644 index 0000000..c685267 --- /dev/null +++ b/.changeset/lazy-seas-tan.md @@ -0,0 +1,5 @@ +--- +"@crbroughton/ts-test-utils": minor +--- + +Add the isArray and isNonArray - Checks if a type is either an array or not an array diff --git a/.github/workflows/bun.yml b/.github/workflows/bun.yml new file mode 100644 index 0000000..883ddac --- /dev/null +++ b/.github/workflows/bun.yml @@ -0,0 +1,34 @@ +name: Bun Tests + +env: + VERSION: v1.10.2 + +on: + push: + branches: [develop, master] + pull_request: + branches: [develop, master] +jobs: + bun_test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + - name: Install dependencies + run: bun install + - name: Run unit tests + run: bun test + - name: Run typechecker + run: bun run typecheck + - uses: actions/upload-artifact@v3 + if: always() + with: + name: bun-report + path: bun-report/ + retention-days: 30 diff --git a/bun.lockb b/bun.lockb index e6a39ea..41dee90 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/index.ts b/index.ts index 9412e8d..e7465b5 100644 --- a/index.ts +++ b/index.ts @@ -11,3 +11,7 @@ export type Excludes = [T] extends [U] ? false : true export type Assignable = U extends T ? true : false export type Extends = U extends T ? true : false + +export type isArray = T extends any[] ? true : false + +export type isNonArray = isArray extends true ? false : true diff --git a/package.json b/package.json index d132d78..22e721e 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "dist" ], "scripts": { - "build": "bun run build.ts", + "typecheck": "tsc --skipLibCheck --noEmit", + "build": "bun run typecheck && bun run build.ts", "lint": "eslint .", "lint:fix": "eslint . --fix", "changeset": "npx changeset", diff --git a/tests/Extends.test.ts b/tests/Extends.test.ts index 18fa93e..3163106 100644 --- a/tests/Extends.test.ts +++ b/tests/Extends.test.ts @@ -9,12 +9,9 @@ describe('Extends tests', () => { type Result = Expect> // ^? }) - it('Failed the includes test when the resulting type does not include the sub-type', () => { + it('Failed the extends test when the resulting type does not extend the sub-type', () => { // @ts-expect-error - Object / Record failing the equality checker - type Result = Expect> + type Result = Expect> // ^? }) }) - - - diff --git a/tests/isArray.test.ts b/tests/isArray.test.ts new file mode 100644 index 0000000..8d55c8a --- /dev/null +++ b/tests/isArray.test.ts @@ -0,0 +1,15 @@ +/* eslint-disable unused-imports/no-unused-vars */ +import { describe, it } from 'bun:test' +import type { Expect, isArray } from '../index' + +describe('isArray tests', () => { + it('Passes the isArray test when the type is an array', () => { + type Result = Expect> + // ^? + }) + it('Failed the isArray test when the type is not an array', () => { + // @ts-expect-error - Fails the exclusion + type Result = Expect> + // ^? + }) +})