@bedard/types
Advanced tools
Comparing version 0.8.3 to 0.9.0
# Changelog | ||
## 0.9.0 | ||
- Add array support to [`ValueOf<T>`](https://github.com/scottbedard/types#valueoft) | ||
## 0.8.3 | ||
@@ -4,0 +8,0 @@ |
@@ -26,3 +26,3 @@ { | ||
}, | ||
"version": "0.8.3" | ||
"version": "0.9.0" | ||
} |
@@ -434,3 +434,3 @@ # `@bedard/types` | ||
Generate a union from the values of `T`. This can be thought of as an opposite to the [`keyof`](https://www.typescriptlang.org/docs/handbook/2/keyof-types.html) operator. | ||
Generate a union from the values of `T`. | ||
@@ -440,3 +440,5 @@ ```ts | ||
type Values = ValueOf<{ foo: number, bar: string }> // number | string | ||
type ArrayValues = ValueOf<Array<string>> // string | ||
type ObjectValues = ValueOf<{ foo: number, bar: string }> // number | string | ||
``` | ||
@@ -443,0 +445,0 @@ |
@@ -40,2 +40,2 @@ export { AllEqual } from './AllEqual' | ||
export const version = '0.8.3' | ||
export const version = '0.9.0' |
@@ -5,4 +5,9 @@ /** | ||
* @example | ||
* ValueOf<Array<string>> // string | ||
* ValuesOf<{ foo: number, bar: string }> // number | string | ||
*/ | ||
export type ValueOf<T extends object> = T[keyof T] | ||
export type ValueOf<T extends object | Array<any>> = T extends Array<infer U> | ||
? U | ||
: T extends object | ||
? T[keyof T] | ||
: never |
@@ -8,5 +8,13 @@ import { | ||
describe('ValueOf', () => { | ||
it('array', () => { | ||
type T = Array<number | string> | ||
type Test = Expect<Equal<number | string, ValueOf<T>>> | ||
}) | ||
it('object', () => { | ||
type Test = Expect<Equal<number | string, ValueOf<{ foo: number, bar: string }>>> | ||
type T = { foo: number, bar: string }; | ||
type Test = Expect<Equal<number | string, ValueOf<T>>> | ||
}) | ||
}) |
49434
1214
471