Repository navigation
Suggestion: typedefs #308
Description
Activity
RyanCavanaugh commented
on Jul 30, 2014 MemberMore actionsI'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?).
// typedef (number) => number MyCallback; interface MyCallback { (n: number): number; } // typedef Vector<SomeDataType> MyVector; interface Vector<T> { } interface MyVector extends Vector<number> {} // 3. With primitive data types // typedef string MyData; // (not possible) // 4. Aliasing classes and interfaces // typedef ReallyLongClassName ShortName; class ReallyLongClassName { } // (not possible; don't make your class names too long to start?) // typedef otherModule.subModule.subModule.Runnable Runnable; module otherModule.subModule.subModule { export class Runnable { } } import Runnable = otherModule.subModule.subModule.Runnable;
I didn't know about the
importstatement.
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 commented
on Jul 31, 2014 ContributorMore actionsBy the way, I like mwisnicki's syntax suggestion:
type Server = http.Server | myApp.Server; type Z = x.y.Z;This would be able to cover (potentially) union types, import statement, and typedef here.
closed by #957 ?
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.
- addedFixedA PR has been merged for this issueA PR has been merged for this issueand removedNeeds More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarifiedNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.
on Nov 3, 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:class S {} export type SS = S; export var SS = S;
Maybe, this suggested typedef is more useful than combination of type alias and var alias.
vadim_lo (@vlomshakov) can you log a separate issue for removing the qualified name restriction on import targets.
- locked and limited conversation to collaborators
on Jun 18, 2018
Suggestion: Allow typedefs for aliasing types, class names and interface names
Use case:
Question: Do we need them?
number, string, boolean).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).