-
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
type alias does not work with classes #5017
Comments
duplicate of #2559 |
A class declaration creates two entities with the same name: A type, which you can use in type annotations, and a constructor function, which you can use in expressions. The problem is that you're exporting an alias for the type, but not the constructor function. If you're using ES6 modules I'd suggest exporting an alias: export class TCommand<TSender, TParam, TThis> {
}
export { TCommand as Command }; If you're using namespaces, you can do the following: namespace Foo {
export class TCommand<TSender, TParam, TThis> {
}
export import Command = Foo.TCommand;
} |
@ahejlsberg
But it produces the unneeded overhead. |
Thanks for the kind words. If you're concerned with the overhead of a derived class, you could write it this way instead: namespace Foo {
export class TCommand<TSender, TParam, TThis>
{
}
export type Command = TCommand<any, any, any>;
export const Command: new () => Command = TCommand;
}
let x: Foo.Command = new Foo.Command(); You'd need to modify the |
@ahejlsberg
one of my use case is that: I want to introduce a new generic type instead an old one - nongeneric. You can look at the code of my framework where i want that replacement |
I defined a class:
and created an alias for the closed type:
export type Command = TCommand<any, any, any>;
now when i try:
export class NextCommand extends Command {
}
the compiler says: Error 1 Cannot find name 'Command'
var cmd = new MOD.mvvm.Command();
Produces the same error
but i can write
var cmd: Command = null;
without errors,
Expected: to allow using this type alias for inheritance purposes.
The problem is that Typescript creates not a true alias
it produces in the output:
but it should produce
That means - we don't need new definitions in the output for alias, but alias should be replaced with the original definition in the output!
The text was updated successfully, but these errors were encountered: