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')
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.
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
There's a pretty similar question & example here.
Most helpful comment
You can do it by declaring a namespace:
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.