Skip to content

Commit

Permalink
Merge pull request #2 from CRBroughton/1-create-isarray-and-isnotarray
Browse files Browse the repository at this point in the history
1 create isarray and isnotarray
  • Loading branch information
CRBroughton authored Apr 18, 2024
2 parents c5bb362 + 8bd5f59 commit a415344
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-seas-tan.md
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions .github/workflows/bun.yml
Original file line number Diff line number Diff line change
@@ -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
Binary file modified bun.lockb
Binary file not shown.
4 changes: 4 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export type Excludes<T, U> = [T] extends [U] ? false : true
export type Assignable<T, U extends T> = U extends T ? true : false

export type Extends<T, U> = U extends T ? true : false

export type isArray<T> = T extends any[] ? true : false

export type isNonArray<T> = isArray<T> extends true ? false : true
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 2 additions & 5 deletions tests/Extends.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ describe('Extends tests', () => {
type Result = Expect<Extends<BaseType, ExtensionType>>
// ^?
})
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<Includes<{ id: number, name: string }, { hobby: string }>>
type Result = Expect<Extends<{ id: number, name: string }, { hobby: string }>>
// ^?
})
})



15 changes: 15 additions & 0 deletions tests/isArray.test.ts
Original file line number Diff line number Diff line change
@@ -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<isArray<{ id: number }[]>>
// ^?
})
it('Failed the isArray test when the type is not an array', () => {
// @ts-expect-error - Fails the exclusion
type Result = Expect<isArray<{ id: string }>>
// ^?
})
})

0 comments on commit a415344

Please sign in to comment.