-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Suggestion: typedefs #308
Comments
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?). // 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 |
By the way, I like mwisnicki's syntax suggestion:
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. |
It seems to me, it's very strange, that import declaration can't make alias for not qualified symbol (see example above - Aliasing classes). 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. |
@vlomshakov can you log a separate issue for removing the qualified name restriction on import targets. |
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).
The text was updated successfully, but these errors were encountered: