Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -36,3 +36,6 @@ jobs: | |
|
||
- name: Run lint | ||
run: npm run lint | ||
|
||
- name: Run TS Type Tests | ||
run: npm run test:types |
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 |
---|---|---|
|
@@ -82,3 +82,5 @@ generates this output: | |
} | ||
} | ||
``` | ||
|
||
Special thanks to Jorge Yero Salazar for providing TS typings! |
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,18 @@ | ||
/** | ||
* Types created by Jorge Yero Salazar (jyeros on GitHub) | ||
*/ | ||
|
||
export type WithFieldMask<T> = { [K in keyof T]?: WithFieldMask<T[K]> | undefined }; | ||
/** | ||
* Creates a new object that copies fields present in field mask from specified source object | ||
* @param sourceObject - object to apply field mask to | ||
* @param fieldMask | ||
* @returns new object created by applying field mask on source object or original entity if source is not an object | ||
*/ | ||
export function applyFieldMask<T>(sourceObject: T, fieldMask: readonly string[]): WithFieldMask<T>; | ||
/** | ||
* Generates field mask that includes all non-function own properties on specified object | ||
* @param object - object to generate field mask from | ||
* @returns - generated field mask | ||
*/ | ||
export function generateFieldMask(object: unknown): string[]; |
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,9 @@ | ||
import { applyFieldMask, generateFieldMask, WithFieldMask } from "./"; | ||
import { expectType } from "tsd"; | ||
|
||
const obj: Record<string, string> = { | ||
foo: "bar", | ||
}; | ||
|
||
expectType<WithFieldMask<Record<string, string>>>(applyFieldMask(obj, ["foo"])) | ||
expectType<string[]>(generateFieldMask(obj)) |
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