Ambient class declaration should allow to declare it implements interface without declaring members of this interface

Topics: General, Language Specification
Jun 24, 2014 at 5:53 AM
Edited Jun 24, 2014 at 5:54 AM

What we have now

For example:
interface IA {
  f(): number;

declare class A implements IA {
Now it produces an error:
Class A declares interface IA but does not implement it: Type 'A' is missing property 'f' from type 'IA'.

What is would be better

I propose that for ambient class declarations ( declare class ) it does not need to describe all members of interfaces described it implements.

May be even introduce new syntax for this cases, like this:
declare class A
  implements IA, IB, IC // interfaces that should need to be implemented (current behavior)
  declare implements ID, IE // just declare this interfaces are implemented
(but I don't think it necessary to have new syntax)

Why it would be better

Sometime it is better to describe existing JavaScript libraries with classes syntax (when it matches TypeScript class inheritance contract), not interface pair of instance/static, because it allow to use in inheritance with TypeScript syntax.
And it still need to allow extend this classes by plugins:
// a.d.ts
interface IA { ... } // open interface
declare class A /* declare ? */ implements IA { ... } // class with TS contract
// a.plugin.d.ts
interface IA { ... } // extends interface, and as a result it extends A class
// mylibrary.ts
class MyA extends A { ... } // standard TS class, and we know it already implements IA
When TS disallow such functionality, it makes to use interface pair pattern, that does not allow using standard TS inheritance.