Reputation: 57
I see the following code in vue github link
declare const RefSymbol: unique symbol
export declare const RawSymbol: unique symbol
export interface Ref<T = any> {
value: T
[RefSymbol]: true
}
what is RefSymbol mean here? i have tried this code:
let test:Ref={value:1}
vscode tell me that I am missing attributes of [RefSymbol]
i had read these questions:
some example code is
interface StringArray {
[index: number]: string;
}
let myArray: StringArray;
myArray = ["Bob", "Fred"];
let myStr: string = myArray[0];
which is quite different with the first example code , it use:true
rather than type :string
, and i did not know how to pass value to [RefSymbol] ,can anyone explain this thing? thanks for any reply
Upvotes: 1
Views: 585
Reputation: 3898
oh it's a javascript declaration where RefSymbol
is a constant.
It's like this.
const key = "size"
const map = {
[key]: 0
}
console.log(map[key]) // 0
typesccript declare also RefSymbol
is declared as unique symbol
which means it is a unique and invariant symbol set as key
Upvotes: 2