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
It's annoying when you have a value with unknown type and can't use it inside .has() or .delete() function. Which doesn't make sense at all. unknown should be allowed and also .has() should assert type.
Solution:
interfaceWeakSet<TextendsWeakKey>{delete<V>(value: V&(unknownextendsV ? unknown : T)): value is Thas<V>(value: V&(unknownextendsV ? unknown : T)): value is T}
Result:
interfaceFoo{foo: string}interfaceBar{bar: string}constfoo: Foo={foo: "foo"}constbar: Bar={bar: "bar"}constunknownFoo: unknown=foosatisfiesFooconstfooSet=newWeakSet<Foo>()if(fooSet.has(unknownFoo)){unknownFoo.foo// Foo}if(fooSet.has(foo)){foo.foo// Foo}if(fooSet.has(bar)){// Error: No overload matches this call.bar.foo// Foo}
Same thing can be done for the WeakMap
The text was updated successfully, but these errors were encountered:
It's annoying when you have a value with
unknown
type and can't use it inside.has()
or.delete()
function. Which doesn't make sense at all.unknown
should be allowed and also.has()
should assert type.Solution:
Result:
Same thing can be done for the
WeakMap
The text was updated successfully, but these errors were encountered: