-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ng-dev): support performing configuration assertions in the getC…
…onfig function (#204) Allow the getConfig function take in a list of assertions functions which will assert against the retrieved config object. Errors from the assertions will be thrown as expected. The returned config object will has the asserted typings. This will allow retrieving the config object already typed, which provides a convenience for cases where getConfig is called on intialization. PR Close #204
- Loading branch information
1 parent
c5da4aa
commit f631e36
Showing
5 changed files
with
63 additions
and
12 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
type UnionToIntersection<U> = (U extends unknown ? (union: U) => void : never) extends ( | ||
intersection: infer I, | ||
) => void | ||
? I | ||
: never; | ||
|
||
type AssertedType<A> = A extends AssertionFn<infer T> ? T : never; | ||
type AllAssertedTypes<A extends readonly AssertionFn<unknown>[]> = { | ||
[K in keyof A]: AssertedType<A[K]>; | ||
}; | ||
type ExtractValuesAsUnionFromObject<T> = T[keyof T & number]; | ||
|
||
export type Assertions<A extends readonly AssertionFn<unknown>[]> = UnionToIntersection< | ||
ExtractValuesAsUnionFromObject<AllAssertedTypes<A>> | ||
>; | ||
export type AssertionFn<T> = (value: Partial<T>) => asserts value is T; | ||
export type MultipleAssertions = AssertionFn<unknown>[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.