Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ES6 symbol types #810

Closed
Gozala opened this issue Sep 17, 2015 · 6 comments
Closed

Add support for ES6 symbol types #810

Gozala opened this issue Sep 17, 2015 · 6 comments
Labels
ES2015+ incompleteness Something is missing

Comments

@Gozala
Copy link
Contributor

Gozala commented Sep 17, 2015

Code along this lines causes an error:

Class List {
  $$typeof: symbol;
  constructor() {
     this.$$typeof = Symbol.for('mylib/symbol')
  }
}
@Gozala
Copy link
Contributor Author

Gozala commented Sep 17, 2015

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.

@eranimo
Copy link

eranimo commented Mar 20, 2017

Has Symbol.iterator support been implemented?

@kvanbere
Copy link

kvanbere commented May 4, 2018

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
    ...
}

@kevinSuttle
Copy link
Contributor

@gajus
Copy link

gajus commented Feb 21, 2019

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.

@SamChou19815
Copy link
Contributor

Symbols support to be supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ES2015+ incompleteness Something is missing
Projects
None yet
Development

No branches or pull requests

8 participants