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

Open
Gozala opened this Issue Sep 17, 2015 · 4 comments

Comments

Projects
None yet
6 participants
@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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

eranimo commented Mar 20, 2017

Has Symbol.iterator support been implemented?

@donkeybonks

This comment has been minimized.

Copy link

donkeybonks 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

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment