typelevel-ts
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -16,2 +16,9 @@ # Changelog | ||
# 0.3.3 | ||
- **New Feature** | ||
- add `RequiredKeys` and `OptionalKeys` types, #33 (@saitonakamura) | ||
- **Bug Fix** | ||
- KeysOfType now handles optional keys, fix #34 (@gcanti) | ||
# 0.3.2 | ||
@@ -18,0 +25,0 @@ |
@@ -15,3 +15,3 @@ /** | ||
export declare type KeysOfType<A extends object, B> = { | ||
[K in keyof A]: A[K] extends B ? K : never; | ||
[K in keyof A]-?: A[K] extends B ? K : never; | ||
}[keyof A]; | ||
@@ -37,1 +37,17 @@ /** | ||
export declare type TaggedUnionMember<A extends object, Tag extends keyof A, Value extends A[Tag]> = Extract<A, Record<Tag, Value>>; | ||
/** | ||
* Extracts required keys as a literal type union | ||
*/ | ||
export declare type RequiredKeys<T> = { | ||
[K in keyof T]: {} extends Pick<T, K> ? never : K; | ||
} extends { | ||
[_ in keyof T]: infer U; | ||
} ? U : never; | ||
/** | ||
* Extracts optional keys as a literal type union | ||
*/ | ||
export declare type OptionalKeys<T> = { | ||
[K in keyof T]: {} extends Pick<T, K> ? K : never; | ||
} extends { | ||
[_ in keyof T]: infer U; | ||
} ? U : never; |
{ | ||
"name": "typelevel-ts", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "Type level programming in TypeScript", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -106,1 +106,11 @@ # TypeScript compatibility | ||
``` | ||
## RequiredKeys<A extends object> and OptionalKeys<A extends object> | ||
Extracts required or optional keys as a literal type union | ||
```ts | ||
type A = { a: string; b: number; x?: string; y?: number } | ||
RequiredKeys<A> // "a" | "b" | ||
OptionalKeys<A> // "x" | "y" | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8394
53
116