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

Generic type inference failure when multiple type provided (with typescript) #584

Closed
kwonoj opened this issue Oct 22, 2015 · 6 comments
Closed

Comments

@kwonoj
Copy link
Member

kwonoj commented Oct 22, 2015

Writing below code via ES5 with commonjs,

Rx.Observable.of(1, 'a').subscribe(console.log);

will be executed with below results

1
a

though some editors might complain by type inference failure.

if same code is written in typescript, now those complaint becomes build time failure

error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'.

Somewhat related to issue #581, not directly though.

@kwonoj
Copy link
Member Author

kwonoj commented Oct 22, 2015

I'm looking into this to try resolve.

@kwonoj
Copy link
Member Author

kwonoj commented Oct 22, 2015

Course caller can explicitly cast like
Rx.Observable.of(<any>1,<any>'a').subscribe(console.log);
, but seems bit hassle.

@staltz
Copy link
Member

staltz commented Oct 23, 2015

Can you write Rx.Observable.of<any>(1, a').subscribe(console.log); instead?

@kwonoj
Copy link
Member Author

kwonoj commented Oct 23, 2015

Yes, that works too. Snippet I took is exaggerated examples of casting hassle. Still it'd be better wouldn't require explicit casting, not sure if it's achievable along with generic based type-safety.

@roganov
Copy link

roganov commented Oct 23, 2015

I don't think that Rx.Observable.of<any>(1, 'a') is a hassle, IMO it's perfectly reasonable TypeScript. It also makes you think whether you really want to mix types.

@kwonoj
Copy link
Member Author

kwonoj commented Oct 23, 2015

Ok, closing now.

@kwonoj kwonoj closed this as completed Oct 23, 2015
@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
None yet
Projects
None yet
Development

No branches or pull requests

3 participants