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

Discussion about typeof navigation #19441

Closed
Alphapage opened this issue Oct 24, 2017 · 6 comments
Closed

Discussion about typeof navigation #19441

Alphapage opened this issue Oct 24, 2017 · 6 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@Alphapage
Copy link

TypeScript Version: 2.5.3

Code

class C {
    constructor(s:string){}
    test(){}
}

const o={C:C}

let c:typeof o.C.prototype

let c2:C=new C('');

let c3:(typeof o).C;

Expected behavior:
(typeof o).C in c3 produces an error.
For now, typeof can navigate to variable and properties only, not types.
It would be great to be able to continue navigate types after a variable casting. So, (typeof o).C and typeof o.C.prototype will produce the same type result.
I prefer (typeof o).C of course.
Actual behavior:
let c3:(typeof o).C; hates parenthesis

@ahejlsberg
Copy link
Member

ahejlsberg commented Oct 24, 2017

This is already possible:

let c3: (typeof o)["C"]["prototype"];

See #11929 for more details.

@ahejlsberg ahejlsberg added the Question An issue which isn't directly actionable in code label Oct 24, 2017
@Alphapage
Copy link
Author

You learn me something, but that doesn't change the navigation: you need to relay on variable navigation.
What I am trying to achieve is to switch from (typeof o) variable/property navigation to type navigation, so let c:C is the same as let c:(typeof o).C (this is what I call type navigation).

@ahejlsberg
Copy link
Member

I'm afraid I don't understand what you're asking for. If T is a type, what exactly are the semantics you expect for a type T.X?

@DanielRosenwasser
Copy link
Member

Additionally, if you want (typeof o).C to be equivalent to (typeof o)["C"], that's not possible given the way the language currently uses . for looking up a type within a namespace.

@Alphapage
Copy link
Author

Yes, I think it could only work for object properties type or module properties type.
@ahejlsberg if T is typeof o, then T.C is C, not typeof o.C (I'm sorry for the very bad explaination).
As soon as you ask typeof o, you enter in a type navigation, so (typeof o).C is the same type as C.
@DanielRosenwasser I understand the way the language is navigating to lookup a type, but I think this could be an advanced feature to think about.

@Alphapage
Copy link
Author

Maybe this feature is confusing for users, so I close the request.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants