Closed AlexJeffcott closed 1 month ago
I think you could do it like this
const Computed = computed(() => null).prototype
if (a instanceof Computed) {}
More future proof solution
if (a?.brand === Symbol.for("preact-signals")) {} // true for any Signal and ReadonlySignal
But actually under the hood ReadonlySignal
still extends Signal
and if you check it instanceof Signal
it will return true with ReadonlySignal
Exactly this change is only on a types level and does not affect any runtime, the type narrowing is just a bit broken in TypeScript it feels like.
I would like to check to see whether a variable is a
computed
. I previously did this usinginstanceof Signal
which was good enough for my purposes.Since upgrading
preact/signals
this no longer works asReadonlySignal
no longer extendsSignal
.This is the change in question.
This is the sort of code I wrote.
This is the sort of code I would like to be able to write.