fix: unsafe embed builder field normalization (#7418)

This commit is contained in:
Suneet Tipirneni
2022-02-07 05:52:10 -05:00
committed by GitHub
parent a921ec7dc5
commit b936103395
4 changed files with 22 additions and 9 deletions

View File

@@ -0,0 +1,14 @@
export interface JSONEncodable<T> {
/**
* Transforms this object to its JSON format
*/
toJSON: () => T;
}
/**
* Indicates if an object is encodable or not.
* @param maybeEncodable The object to check against
*/
export function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown> {
return maybeEncodable !== null && typeof maybeEncodable === 'object' && 'toJSON' in maybeEncodable;
}