You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class_: T,
...args: ConstructorParameters<T>): HasTypedConstructor<T>=>newclass_(...args)asHasTypedConstructor<T>declareconstreplacedUndefined: uniquesymbol/** * recursively removes `undefined` properties from an object type. used by the `optionalProperties` function * only useful when using the `exactOptionalPropertyTypes` compiler option. this type has no effect if it's disabled * * @example * type Foo = RemoveUndefinedPropertiesRecursive<{ a?: number | undefined, b: string | undefined }> // { a?: number, b: string | undefined } */// TODO: rewrite this, it sucks (currently turns properties into `never` instead of removing them)// should probably be moved to types and then exported when its fixedtypeOptionalProperties<Textendsobject>=|TsToolbeltFilter<{[KinkeyofT]: ListOf<T[K]>extends infer Union
? // now iterate over the union and recursively call this type on any object types within the union:{[UnionIndexinkeyofUnion]: Union[UnionIndex]extendsobject
? OptionalProperties<Union[UnionIndex]>
: Replace<Union[UnionIndex],undefined,typeofreplacedUndefined>}[Keys<Union>]
: never},typeofreplacedUndefined,'<-contains'>&ReplaceValuesRecursive<T,undefined,never>/** * recursively removes `undefined` properties from an object. * useful when using the `exactOptionalPropertyTypes` compiler option */exportconstoptionalProperties=<Textendsobject>(object: T): OptionalProperties<T>=>(Object.entries(object)as[string,unknown][]).reduce((prev,[key,value])=>{letresultif(Array.isArray(value)){result=value.map(optionalProperties)}elseif(typeofvalue==='object'&&value!==null){result=optionalProperties(value)}else{result=value}return{
...prev,
...(value===undefined ? {} : {[key]: result}),}},{}asOptionalProperties<T>)
The text was updated successfully, but these errors were encountered:
should probably be moved to types and then exported when its fixed
https://api.github.com/DetachHead/ts-helpers/blob/6c4b860f5fda1f2e96a416e677cd60af2e216b97/src/functions/misc.ts#L333
The text was updated successfully, but these errors were encountered: