Code along this lines causes an error:
Class List {
$$typeof: symbol;
constructor() {
this.$$typeof = Symbol.for('mylib/symbol')
}
}
I did not quite figured out how to add a primitive type support and at this point I don't have enough time to digg into to do it. So I have created this libdef for my use:
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
declare class Symbol {
static (value?:any): symbol;
static for(key:string): symbol;
static keyFor(symbol:symbol): string;
toString(): string;
valueOf(): symbol;
// Well-known symbols
static iterator: symbol;
static match: symbol;
static replace: symbol;
static search: symbol;
static split: symbol;
static hasInstance: symbol;
static isConcatSpreadable: symbol;
static unscopables: symbol;
static species: symbol;
static toPrimitive: symbol;
static toStringTag: symbol;
}
type symbol = Symbol;
I'm happy to send a pull to include it into core.js until proper support is built.
Has Symbol.iterator support been implemented?
This would be really good to have because it is a common use-case with React Redux to use symbols for action namespacing (and slightly better performance, too).
Our current codebase massively fouls with flow and we've got a lot of $FlowFixMes caused by lack of Symbol support and support for symbols as map keys. ie
export const SOME_FOO = Symbol('SOME_FOO');
// ...
import { SOME_FOO } from './some/action/type';
export const {
SOME_FOO: doSomeFoo,
// ^ flow error, symbol not supported / can't use as map key
...
}
Is there any plan to support Symbols?
https://flow.org/try/#0MYewdgzgLgBAYiEBlAngWwEYgDYwLwyqY4AUA5HAPKVkCUA3AFCiSwBCAhgE5Fa4G9SZNgEEASnSaMoKAA4BTGJwBeAFTmKCAbwA+jAJABqGQoBcME-JAAzeIkHYANIxiuYhgG4dsAV3kBGc2guAEswAHNGHQBfGB0YXQNjDXNLGyVuB2c3dy9feQAmczAfTHkuKOipFmgYDG58GBJ65XMVdQVafAA+BKrGRnquEi0DS3MEZHQ+bJh9PL8imH9GaIYgA
Currently typeof construct is useless for differentiating object shape, and symbol cannot be used as a literal value.
Most helpful comment
Has Symbol.iterator support been implemented?