-
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
Why doesn't TypeScript provide a way to implement an interface on the static side? #17545
Comments
@zheeeng from a type checking point of view, you absolutely can do exactly what you want and with almost identical syntax: export type Cls = typeof Cls;
export const Cls: ClassInterface = class implements InstanceInterface {
constructor(public foo: string) {}
static baz() {
console.log('I override the interface baz.');
}
bar() {
return this.foo;
}
}; Also, comparing TypeScript to Java makes no more sense than comparing JavaScript to Java. |
@aluanhaddad Thx, it works and is elegant! |
Related: #1263, #13462. class C {
static x() { return 0; }
}
function f(cls: { x(): number }) {
return cls.x();
}
f(C); // Works! |
@andy-ms @RyanCavanaugh What if libs like React requires that developer must manually set the static property displayname on each class component? The typescript friendly hints will help a lot. |
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
Code
I'm new to typescript and I'm wondering why not typescript add the class shape interface likes example below?
As I know, Java8 added the static method defining and default implements.
The text was updated successfully, but these errors were encountered: