Skip to content

WAITING FOR TSC 1.8: refactor(patches): move operator stubs from Observable.ts to patch files #1284

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

Closed

Conversation

masaeedu
Copy link
Contributor

@masaeedu masaeedu commented Feb 2, 2016

Use new external module augmentation feature to move Observable stubs into patch files. See #1193

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

Appreciate for taking effort for this!

I tried this PR and found somewhat unexpected behavior, while consumption of augmented module works editor supports for typing isn't as below,

image

image

none of type definitions are now being supported by editors.

This change solves build time detection of what issue #1193 points but this seems quite regression that prevents daily usage of type definitions. I assume current editor's TypeScript engines are yet able to support those.

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

For checking in this changes, I came to bit hesitate by this change loses existing availability of typings - What do you think? Is there'll be immediate resolution for this? /cc @saneyuki, @Blesh also for visibility.

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

@kwonoj Are you importing the appropriate operators? Also, could you provide a testcase I can stick in a file and play around with?

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

@masaeedu That's occurring even importing full set, import * as Rx from... Since full set imports every operator, I'd expect it work out of box as same as before.

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

Just clarify, I'm currently using VS code. Curious if other editor / IDE might have same behavior.

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

@kwonoj Weird. Trying to setup a test now. Just to be sure, have you set your "typescript.tsdk" setting at the user or workspace level to the latest typescript?

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

have you set your "typescript.tsdk" setting at the user or workspace level to the latest typescript?

: No, I'm using out of box configuration. Maybe that's reason?

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

@kwonoj Ok, so that's probably one thing to fix. I got some great help with how to do this in microsoft/vscode#1771. However, I already have this set up and can reproduce the issue you're seeing when I import * as Rx from 'rxjs/Rx' (but not when importing individual patch files).

The issue is that because we're not re-exporting the contents of the patch files in the Rx.ts file, all the import './add/operator/foo' lines have no effect on the generated .d.ts file. What we want is to do export * from './add/operator/foo'. I've tried changing a few of the imports to re-exports and it seems to work.

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

What we want is to do export * from './add/operator/foo'

: What happens if import operators separately?

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

@kwonoj You mean if I don't use the rxjs/Rx module and import directly from add/operator/foo? That scenario works fine for me right now. Only the operators I import are available on an Observable.

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

if I don't use the rxjs/Rx module and import directly from add/operator/foo?

: Yes, that was the case.

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

When I tried both (importing Rx / importing operator individually) were not able to provide type definitions.

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

So this is the scenario I'm trying right now:

// @filename:main.ts
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/buffer';

var obs = Observable.of(1, 2, 3);
obs.bu // I press Ctrl+Space to get autocomplete options here

The autocomplete options I get look like this:

Image of Yaktocat

(please ignore tslint squigglies 😄). Once I change the corresponding imports in Rx.ts to export * froms, they start working the same way.

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

@kwonoj Hopefully this is what the expected behavior is?

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

Cool, it's lovely. We still need to test out couple of more editor / IDE to ensure this works though. (anyone uses other editor than VS code?)

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

We still need to test out couple of more editor / IDE to ensure this works though.

: I think it'd be ok as long as other editor's not regressed. losing all type intellisense is case I'd like to avoid.

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

@kwonoj I can test out Atom. There's no rush to get this merged, I don't think rebasing this should be too difficult because there's not too many people fooling around with the patch files.

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

@kwonoj Also, now that I've fixed the Rx.ts file, the scenario you were talking about works 😄 :

image demonstrating how Rx.ts import works

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

Thanks, let's test out couple of more and rebase. Might need see how does reexport looks like.

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

the scenario you were talking about works

: Cool, one step forward for better typing experiences :)

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

I did however have to nuke the export var _void: void; in the patch files to make the re-exports work. Do you know if this is still needed?

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

this is still needed

Nope. That was introduced due to #1010, patch operator type definition becomes empty since there's nothing exported. If there's real export, that doesn't necessarily required anymore.

Use new external module augmentation feature to move Observable stubs into patch files. See ReactiveX#1193
Change all `import './add/operator/foo'` in Rx.ts to `export * from './add/operator/foo'`, in order to ensure the module augmentations appear in the generated Rx.d.ts file. Also remove `export var _void`s to
avoid conflicts.
@masaeedu masaeedu force-pushed the addObservableInterfacePatches branch from 1905fba to 142ebdb Compare February 2, 2016 09:36
@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

What about Rx.KitchenSink? doesn't it need to be updated as well?

@@ -1,6 +1,4 @@
import {Observable} from '../../Observable';
import {combineLatestStatic} from '../../operator/combineLatest';

Observable.combineLatest = combineLatestStatic;

export var _void: void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this still needed? does typings contains exports after removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by that. This file is still considered an external module after removal of export var _void if that's what you mean, because it has top level imports.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer #1010 I mentioned. If there isn't any export makes d.ts to be empty, it makes consumer in trouble. So question's is there anything exported after removing this and type definition's published. I assume operator includes augmentation does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kwonoj Yes, I ran into that issue. Discussing with the TypeScript folks in microsoft/TypeScript#6022

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For our side of interim, we could leave this as same as before, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right. I'll revert the _void: void removals and re-exports for the observable patches.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go that way. I don't think this need to block this whole PR. (export void if empty, remove if it's unnecessary)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be reverting these to help the PR go through, but the good news is that empty .d.ts files won't be a problem for the consumer starting in tomorrow's builds (in other words we don't need the _void: void anymore).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's cool news, but it's starting from tomorrow's nightly version, right? thinking about discussion for min version support at #1288 (comment), that might need to be hold off for moment :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kwonoj Yeah, unfortunately it looks like we'll have to let this and #1288 stew for a while. 😞

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

@kwonoj I guess so. I wasn't actually aware of the existence of Rx.KitchenSink. Is the goal of that file to export everything in Rx plus some extras? If so it would probably be a good idea to only do export * from './Rx' and then export the extras, instead of duplicating all of them.

buffer: (closingNotifier: Observable<any>) => Observable<T[]>;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be silly but what do you think about augmenting the module before the prototype assignment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luisgabriel I don't mind either approach. Is there a reason you prefer that style?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes more sense to me to declare an interface first and then implement it. But this is not a big deal. I'm just commenting to see if this makes sense to someone else other than me. ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do as @luisgabriel said when I gave attempt. Honestly I think it's minor and does not impact to anything though.

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

Is the goal of that file to export everything in Rx plus some extras?

: Yes, it have few additional operators in additions to Rx.

If so it would probably be a good idea to only do export * from './Rx' and then export the extras, instead of duplicating all of them.

: if that works I think that'd better. I tried those while ago but wasn't able to make it.

@david-driscoll
Copy link
Member

Atom updates fairly regularly against typescript itself, so the definitions do propagate properly it looks like.

image

image

@david-driscoll
Copy link
Member

Does anyone know of a way that this can be applied to static methods as well? Users will still sett Observable.combineLatest even if they haven't imported rxjs/add/observable/combineLatest.

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

that this can be applied to static methods as well

: So far I understand, augmentation's instance for class / interface and not applicable for static.

@david-driscoll
Copy link
Member

I know, just a random item for thought. Not meant as anything to block, just maybe someone knew something. :)

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

, just maybe someone knew something

: Yup, sorry for repeating already-known-to-unknown :) Once this changes are checked in, let's track those as separate issue if needed.

@benlesh
Copy link
Member

benlesh commented Feb 2, 2016

Just marking this as blocked and discussion until it's worked out.

Also it needs to be rebased.

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

@david-driscoll I think namespace merging might work for the static methods.

@masaeedu
Copy link
Contributor Author

masaeedu commented Feb 2, 2016

@david-driscoll Yup, works great:

import {Observable} from '../../../Observable';
import {WebSocketSubject} from '../../../observable/dom/WebSocketSubject';

Observable.webSocket = WebSocketSubject.create;

declare module '../../../Observable' {
  namespace Observable {
    export let webSocket: typeof WebSocketSubject.create;
  }
}

Although we should probably fix the typeof WebSocketSubject.create here eventually for the reasons discussed earlier.

@kwonoj
Copy link
Member

kwonoj commented Feb 2, 2016

Let's make static method as separate discussion. This PR itself has quite amount of changes.

@david-driscoll
Copy link
Member

That's fine, @masaeedu you want to make a separate PR or should I? (I don't care)

@robwormald
Copy link
Contributor

same as #1288, i'm definitely for this change but it needs to wait until the functionality is in the released TS compiler.

luisgabriel referenced this pull request Feb 3, 2016
@kwonoj kwonoj changed the title refactor(patches): move operator stubs from Observable.ts to patch files WAITING FOR TSC 1.8: refactor(patches): move operator stubs from Observable.ts to patch files Feb 3, 2016
@masaeedu
Copy link
Contributor Author

Now tracked by #1388

@masaeedu masaeedu closed this Feb 24, 2016
@lock
Copy link

lock bot commented Jun 7, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants