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 property (dotted) access syntax for types #12962

Closed
normalser opened this issue Dec 15, 2016 · 3 comments
Closed

Allow property (dotted) access syntax for types #12962

normalser opened this issue Dec 15, 2016 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@normalser
Copy link

This works:

interface Test {
    A: 'a' | 'b' | 'c'
}

function test(a: Test['A']) {
}
test('a')

Would be nice if we could use it as that:

function test2(a: Test.A) {
}
test2('a')
@ahejlsberg
Copy link
Member

You can do it by declaring a namespace:

interface Test {
    A: 'a' | 'b' | 'c'
}
namespace Test {
    export type A = Test['A'];
}

function test(a: Test.A) {
}
test('a')

You're effectively proposing that we do this automatically. But, because you can already do it today, it would be a breaking change to do it automatically because we'd potentially conflict with code such as the example.

@ahejlsberg ahejlsberg added the Suggestion An idea for TypeScript label Dec 15, 2016
@normalser
Copy link
Author

normalser commented Dec 15, 2016

Thank you @ahejlsberg
Yes - I was hoping that it would do this automatically but I understand the implication.
Maybe it could throw an error only if it detected such conflict

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Dec 17, 2016

There's a pretty similar question & example here.

@RyanCavanaugh RyanCavanaugh added Question An issue which isn't directly actionable in code and removed Suggestion An idea for TypeScript labels Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants