Closed
Description
Suggestion: Allow typedefs for aliasing types, class names and interface names
Use case:
// 1. Use case overlaps with interface functions types and is even uglier
typedef (number) => number MyCallback;
// 2. With generics
typedef Vector<SomeDataType> MyVector;
// 3. With primitive data types
typedef string MyData;
// 4. Aliasing classes and interfaces
typedef ReallyLongClassName ShortName;
typedef otherModule.subModule.subModule.Runnable Runnable;
Question: Do we need them?
- Assigning a name to function types is already possible using interface function types. In my opinion, their syntax is nicer and we should not introduce another syntax for the same feature.
- This can help minimzing the amount of typing.
- According to the last comment of the original CodePlex issue, this can help commenting the code. It does however introduce another layer of name aliasing for names which are already short (
number, string, boolean
). - This can also help minimzing the amount of typing, especially for accessing external classes and interfaces inside deeply nested modules. Aliasing modules themselves would also be imaginable.
The original CodePlex issue: http://typescript.codeplex.com/workitem/119
Note that many of the given code examples are already covered by #14 (union types).
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
RyanCavanaugh commentedon Jul 30, 2014
I'd like to see more compelling examples of things that you can't do with existing syntax; we don't want to have a bunch of ways to accomplish exactly the same thing.
The only cases that aren't already possible are re-naming the primitive types, which I think many people would argue is a bad thing to do in the first place, and shortening a class name where the class name doesn't come from a module (which is sort of a code smell to begin with -- a class name so long you can't even use it as-is?).
ComFreek commentedon Jul 30, 2014
I didn't know about the
import
statement.I agree with you on all points except for aliasing the generic interface (or class) since it's semantically not the same as a typedef. But I wouldn't add typedefs for this sole reason either.
saschanaz commentedon Jul 31, 2014
By the way, I like mwisnicki's syntax suggestion:
This would be able to cover (potentially) union types, import statement, and typedef here.
teppeis commentedon Nov 2, 2014
closed by #957 ?
danquirk commentedon Nov 3, 2014
Yeah, type aliases are essentially this with a well defined set of rules. If people have issues with the current implementation do comment over in the type aliases issues or log bugs as appropriate.
vlomshakov commentedon Nov 14, 2014
It seems to me, it's very strange, that import declaration can't make alias for not qualified symbol (see example above - Aliasing classes).
Now I have to use next way to do this:
Maybe, this suggested typedef is more useful than combination of type alias and var alias.
mhegazy commentedon Nov 14, 2014
@vlomshakov can you log a separate issue for removing the qualified name restriction on import targets.
3 remaining items