Skip to content

Commit 7a730ff

Browse files
authored
Branding Ref so types with a value property aren't incorrectly unwrapped. (#199)
* giving Ref a brand so that other types with a value property aren't inferred and unwrapped * changing to marketdial org * 0.3.5 * using brand as the property key * removing concrete runtime level appearances of _refBrand
1 parent 0eb771c commit 7a730ff

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/reactivity/ref.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ type BailTypes = Function | Map<any, any> | Set<any> | WeakMap<any, any> | WeakS
1111
// RelativePath extends object -> true
1212
type BaseTypes = string | number | boolean;
1313

14+
declare const _refBrand: unique symbol;
1415
export interface Ref<T> {
16+
readonly [_refBrand]: true;
1517
value: T;
1618
}
1719

@@ -91,6 +93,7 @@ interface RefOption<T> {
9193
set?(x: T): void;
9294
}
9395
class RefImpl<T> implements Ref<T> {
96+
readonly [_refBrand]!: true;
9497
public value!: T;
9598
constructor({ get, set }: RefOption<T>) {
9699
proxy(this, 'value', {
@@ -139,7 +142,7 @@ export function isRef<T>(value: any): value is Ref<T> {
139142

140143
// prettier-ignore
141144
type Refs<Data> = {
142-
[K in keyof Data]: Data[K] extends Ref<infer V>
145+
[K in keyof Data]: Data[K] extends Ref<infer V>
143146
? Ref<V>
144147
: Ref<Data[K]>
145148
}

0 commit comments

Comments
 (0)