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 Symbol.observable to Observable interface #8

Closed
appsforartists opened this issue Dec 7, 2016 · 3 comments
Closed

Add Symbol.observable to Observable interface #8

appsforartists opened this issue Dec 7, 2016 · 3 comments

Comments

@appsforartists
Copy link
Member

appsforartists commented Dec 7, 2016

Can't add the [$$observable] line of

export interface Observable<T> {
  subscribe(listener: Observer | Next): Subscription;
  [$$observable](): Observable<T>;
}

because $$observable throws this error:

TS1169: A computed property name in an interface must directly refer to a built-in symbol.

Symbol didn't exist until Safari 8, so using Symbol.observable rather than $$observable would affect our compatibility with Safari 8 for no user-justifiable reason.

@appsforartists
Copy link
Member Author

microsoft/TypeScript#5579 might be related.

@appsforartists
Copy link
Member Author

Using Symbol also make the polyfill eligible for dead code elimination, so you end up writing something like

if (typeof Symbol !== 'function') {
  IO.prototype[$$observable] = function() { 
    return this; 
  }
}

which would never run, because Symbol.observable would be a reference error before you even got there.

@appsforartists
Copy link
Member Author

This has been fixed for a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant