Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 create isarray and isnotarray #2

Merged
merged 5 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }>>
// ^?
})
})
Loading