-
Notifications
You must be signed in to change notification settings - Fork 3k
Improve from #1528
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
Improve from #1528
Conversation
interface Iterable<T> { | ||
[Symbol.iterator](): Iterator<T>; | ||
} | ||
interface Iterator<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's difference this to what we're currently using in es6-shim
type definitions? looks identical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
es6-shim
doesn't actually shim in Symbol
, so the IteratorShim<T>
doesn't have the appropriate [Symbol.iterator]()
attached to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what I meant was Iterator
specific. Sorry for confusion.
df137b4
to
f19d06a
Compare
Rebased. |
export type ArrayOrIterator<T> = Iterator<T> | ArrayLike<T>; | ||
export type ObservableInput<T> = SubscribableOrPromise<T> | ArrayOrIterator<T>; | ||
export interface Observablesque<T> { | ||
[Symbol.observable](): Subscribable<T>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small thing here. [Symbol.observable]()
should return a type that is Subscribable<T>
AND Observablesque<T>
at a minimum. (Similar to how Iterators have a Symbol.iterator
on them)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know what? Scratch that. Don't worry about it, for the purposes of the internals of our library where this is being used, we don't care.
LGTM |
The last thing I thought about, from a release perspective. Should we copy that I think at the time being this mainly applies to commonjs builds only I think. |
@david-driscoll what about publish it into typings and let it be installed as same as other type shims? |
I like the idea. Proposed name I'll also add some notes to https://github.com/ReactiveX/rxjs/blob/master/doc/installation.md to direct users to install the typing if they are compiling their TypeScript project with |
I'll go through changes once again and check this in later today to tomorrow. type definition shim can be dealt with separate PR, I assume. |
Sure thing, as long as the name works I'll start the work getting it into the |
Can we test this against core-js and the like? Anything that introduces types like Symbol to the global namespace is almost guaranteed to cause a huge amount of pain downstream... |
@david-driscoll , let me hold off check in bit - would you able to clarify @robwormald 's request? |
@robwormald does core-js have a like typescript typings? This change doesn't actually shim The following just won't work, unless the TypeScript code has export interface Observablesque<T> {
[Symbol.observable](): Subscribable<T>;
} The problem is interface Symbol { }
interface SymbolConstructor {
iterator: symbol;
}
declare var Symbol: SymbolConstructor;
interface Iterable<T> {
[Symbol.iterator](): Iterator<T>;
}
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
return?(value?: any): IteratorResult<T>;
throw?(e?: any): IteratorResult<T>;
} |
Give me all of your PRs, @robwormald |
@david-driscoll @kwonoj I labelled this "LGTM" a while ago... is there still work being done here? |
Change itself is ready, wanted to ensure and clarify @robwormald 's question. I'm planning to check this in around tomorrow. |
Along the lines of the discussion with @kwonoj and @robwormald I've created a typings repo, for https://github.com/david-driscoll/rxjs-symbol-typings If someone wants to move this to Once this gets merged into the typings registry, I can create a follow up PR that removes |
This change also introduces a shim for es5 to include the required bits.
f19d06a
to
e0f211a
Compare
rebased |
e0f211a
to
642c334
Compare
@david-driscoll looks like there's still a build failure. Might want to dig into that. |
642c334
to
aa17119
Compare
Actually it looks like it has something to do with the merged mocha changes. cc/ @kwonoj |
@Blesh Nah, it was my bad, I missed something on rebase... third time is the charm I think |
Merged with c6ef2e8, thanks @david-driscoll |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description:
I tried to keep the changes down to a minimum here, if we feel like they need to split out into several PR's I'm okay with that. This may add pain for consumers that don't use the
es6.lib.d.ts
declarations. There is work on the TypeScript to help with this pain, see microsoft/TypeScript#6990 and microsoft/TypeScript#6974. Today we could point them atspec/es5.d.ts
as a small shim they can use.Iterator<T>
withIterable<T>
.Observablesque<T>
which uses the symbol.NOTE: The reason these are grouped is both 1 and 2, are changes that break compilation. We have to shim in
SymbolConstructor
andIterable<T>
.Details:
Basically what's going on...
Right now we use
Iterator<T>
as part ofObservableInput<T>
but really the interface we're looking for (in code that is) isIterable<T>
. So this change fixes that.Also we declare
Symbol.observable
but this isn't declared anywhere in the interfaces, so there isn't an easy way to add that toObservableInput<T>
without an interface.