Skip to content

Commit

Permalink
test: add test for UnionKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Mar 24, 2024
1 parent d11fb09 commit 42d2764
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/type-plus/src/union_keys.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { it } from '@jest/globals'
import { testType, type UnionKeys } from './index.js'

it('gets the keys of an object', () => {
testType.equal<UnionKeys<{ a: 1, b: 2 }>, 'a' | 'b'>(true)
})


it('returns known keys', () => {
type Foo = {
a: string
b: string
}

// @ts-ignore
function foo<T>(input: UnionKeys<Foo & T>): void {
input = 'a'
input = 'b'
// @ts-expect-error
input = 'c'

let r: keyof (Foo & T)
r = 'a'
r = 'b'
// @ts-expect-error
r = 'c'
}
})

0 comments on commit 42d2764

Please sign in to comment.