Skip to content

Commit 5441c8e

Browse files
authored
Fix Metric.isMetric runtime brand (#6822)
1 parent 89ce5f3 commit 5441c8e

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

.changeset/fix-metric-is-metric.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
Fix `Metric.isMetric` to recognize metrics using their current runtime brand.

packages/effect/src/Metric.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,19 +2021,15 @@ class MetricTransform<in Input, out State, in Input2> extends Metric$<Input2, St
20212021
* ```ts import.meta.vitest
20222022
* import { Metric } from "effect"
20232023
*
2024-
* const counter = Metric.counter("requests")
2025-
* const gauge = Metric.gauge("temperature")
2026-
* const notAMetric = { name: "fake-metric" }
2027-
*
2028-
* const checks = [Metric.isMetric(counter), Metric.isMetric(gauge), Metric.isMetric(notAMetric), Metric.isMetric(null)]
2029-
* checks // => [false, false, false, false]
2024+
* Metric.isMetric(Metric.counter("requests")) // => true
2025+
* Metric.isMetric({ name: "requests" }) // => false
20302026
* ```
20312027
*
20322028
* @category guards
20332029
* @since 4.0.0
20342030
*/
2035-
export const isMetric = (u: unknown): u is Metric<unknown, never> =>
2036-
Predicate.hasProperty(u, "~effect/Metric") && u["~effect/Metric"] === "~effect/Metric"
2031+
export const isMetric = (u: unknown): u is Metric<never, unknown> =>
2032+
Predicate.hasProperty(u, TypeId) && u[TypeId] === TypeId
20372033

20382034
/**
20392035
* Represents a Counter metric that tracks cumulative numerical values over

0 commit comments

Comments
 (0)