Permit type alias declarations inside a class
See original GitHub issueI normally want my class declaration to be the first thing in my file:
module foo {
/** My foo class */
export class MyFoo {
}
}
So when I want to declare an alias, I don’t like the fact that my class has been pushed down further:
module foo {
type foobar = foo.bar.baz.FooBar;
/** My foo class */
export class MyFoo {
}
}
I suggest the following be permitted:
module foo {
/** My foo class */
export class MyFoo {
type foobar = foo.bar.baz.FooBar;
}
}
Since type foobar
is just a compile-time construct, and if people want to write it that way, then they should be permitted to do so. Note that the type foobar
is private to the class. It should not be permissible to export foobar
.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:148
- Comments:75 (17 by maintainers)
Top Results From Across the Web
Type Aliases vs Interfaces in TypeScript - DEV Community
Type aliases work in a similar manner. Wherever you annotate a type by its alias, the alias will evaluate to the type(s) that...
Read more >Is it possible to declare a nested type alias using a forward ...
No, you cannot put something inside of a class except by actually writing it inside the class definition. It's not an issue of...
Read more >Aliases and typedefs (C++) - Microsoft Learn
You can use an alias declaration to declare a name to use as a synonym for a previously declared type. (This mechanism is...
Read more >Type alias, alias template (since C++11) - cppreference.com
Like any template declaration, an alias template can only be declared at class scope or namespace scope. The type of a lambda expression ......
Read more >PEP 613 – Explicit Type Aliases
Type aliases are valid within class scope, both implicitly ( x ) and explicitly ( y ). If the line should be interpreted...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m running into this pattern:
I have a generic class and would like to create a type alias that references a specialized generic type expression that is only valid for that particular class scope, for example instead of:
It would be great if I could alias that complex type expression (
Array<{ val: T }>
) to a locally scoped type. e.g.I’m not exactly sure how to effectively work around this. Both the solutions provided @RyanCavanaugh and the original one mentioned by @NoelAbrahams would still a require to parameterize the type alias. E.g:
But that’s not really what I’m looking for… The whole idea was to make it simpler and more readable… (also, if part of the workaround meant I had to use some strange merging between a class and a namespace I would rather just have nothing at all and write all the types verbosely).
Here’s an example where this feature would be very useful.
could become
I’m sorry to see this proposal was declined because a good example was not provided on time. I hope this will be reconsidered.