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

Allow typeof on arbitrary expression #2542

Closed
mwisnicki opened this issue Mar 29, 2015 · 3 comments
Closed

Allow typeof on arbitrary expression #2542

mwisnicki opened this issue Mar 29, 2015 · 3 comments
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@mwisnicki
Copy link

At the moment compiler insists on having valid identifier on right side of typeof so following code is not valid:

var x : typeof (1+ 2);
var y : typeof this;

even though it's possible to assign the expression to variable and then capture the type form that:

var x_ = 1+2;
var x = typeof x;
var y_ = this;
var y = typeof y_;

I propose to allow capturing type of any valid expression. The expression itself wouldn't be evaluated.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 30, 2015

How is that different from:

var x = typeof (1+2);
var y = typeof this;

@RyanCavanaugh
Copy link
Member

@mhegazy we're talking about type-position typeof, not value-position.

typeof this seems useful, but more allowing more complex expressions is trickier. It's not at all apparent to a casual observer that typeof f(x) in type positions only won't evaluate the function call; the restriction to dotted identifiers is a bit of a safeguard in this respect.

Other than typeof this, what kind of uses cases do you want this for?

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Needs More Info The issue still hasn't been fully clarified labels Mar 30, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Feb 20, 2016

duplicate of #6606

@mhegazy mhegazy closed this as completed Feb 20, 2016
@mhegazy mhegazy added Duplicate An existing issue was already created and removed Needs More Info The issue still hasn't been fully clarified labels Feb 20, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants