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
Should we consider giving this a somewhat-precise type signature, instead of returning any?
I'm not sure whether this would be appropriate or not, but here's a take on a function signature that preserves most type information for supported types, while stripping out methods for custom types.
It might not be perfect, but we should be able to get something close enough that the type information comes in handy much more often than it gets in the way (by forcing a cast).
exportconstclone=<Value>(value: Value)=>deserialize(serialize(value))asCloned<Value>;constserialize=(value: unknown)=>// deno-lint-ignore no-explicit-any(Denoasany).core.serialize(value)asUint8Array;constdeserialize=(bytes: Uint8Array)=>// deno-lint-ignore no-explicit-any(Denoasany).core.deserialize(bytes)asunknown;// deno-fmt-ignoretypeCloned<Value>// preserve supported value types as-is=ValueextendsCloneablePrimitives|CloneableValues
? Value
: RW<Value>extendsCloneablePrimitives|CloneableValues
? Value// deno-lint-ignore ban-types
: ValueextendsFunction
? never// recur over parameters of supported collection types
: RW<Value>extendsMap<infer K, infer V>
? Map<Cloned<K>,Cloned<V>>
: RW<Value>extendsSet<infer V>
? Set<Cloned<V>>
: RW<Value>extendsArray<unknown>|Record<string,unknown>
? {[KeyinkeyofValue]: Cloned<Value[Key]>}
: never;typeCloneable=|CloneablePrimitives|CloneableCollections|CloneableValues;typeCloneablePrimitives=|bigint|boolean|null|number|string|undefined;typeCloneableCollections=|Set<Cloneable>|Map<Cloneable,Cloneable>|Array<Cloneable>|{[key: string]: Cloneable};typeCloneableValues=|ArrayBuffer|ArrayBufferView|BigInt|Blob// deno-lint-ignore ban-types|Boolean|Date|Error|EvalError// deno-lint-ignore ban-types|Number|RangeError|ReferenceError|RegExp// deno-lint-ignore ban-types|String|SyntaxError|TypeError|URIError;/** * Removes readonly modifiers within a type (making it [r]ead[w]rite). * * We use this to help match against types while ignoring readonly modifiers. */typeRW<T>={-readonly[PinkeyofT]: RW<T[P]>;};
Spec: whatwg/html@1b5099f
The text was updated successfully, but these errors were encountered: