From f2f682e561332fd51111d3f72ef6282ef449519d Mon Sep 17 00:00:00 2001 From: Dan Freeman Date: Fri, 18 Aug 2017 18:38:17 -0600 Subject: [PATCH 1/4] Class-based approach --- types/ember/index.d.ts | 175 +++++++++++++++++----------- types/ember/test/array-proxy.ts | 2 +- types/ember/test/detect-instance.ts | 20 ++++ types/ember/test/detect.ts | 20 ++++ types/ember/test/extend.ts | 4 +- types/ember/tsconfig.json | 2 + 6 files changed, 149 insertions(+), 74 deletions(-) create mode 100644 types/ember/test/detect-instance.ts create mode 100644 types/ember/test/detect.ts diff --git a/types/ember/index.d.ts b/types/ember/index.d.ts index fc32770..c9bcdba 100644 --- a/types/ember/index.d.ts +++ b/types/ember/index.d.ts @@ -200,57 +200,74 @@ type EmberClassArguments = Partial & { type EmberMixin = Ember.Mixin | T; -interface EmberClassConstructor { - new (...args: any[]): T; - prototype: T; - - create>( - this: EmberClassConstructor, - args?: Extensions & ThisType): Extensions & Instance; - - createWithMixins>( - this: EmberClassConstructor, +type Create = >( + this: new () => Instance, + args?: Extensions & ThisType) + => Extensions & Instance; + +type CreateWithMixins = >( + this: new () => Instance, + mixin1: EmberMixin, + args?: Extensions & ThisType) + => Extensions & Instance & M1; + +type Extend = + (>( + this: new () => Instance, + args?: Extensions & ThisType) + => EmberClassConstructor) + & + (>( + this: new () => Instance, mixin1: EmberMixin, - args?: Extensions & ThisType): Extensions & Instance & M1; -} + args?: Extensions & ThisType) + => EmberClassConstructor) + & + (>( + this: new () => Instance, + mixin1: EmberMixin, mixin2: EmberMixin, + args?: Extensions & ThisType) + => EmberClassConstructor) + & + (>( + this: new () => Instance, + mixin1: EmberMixin, mixin2: EmberMixin, mixin3: EmberMixin, + args?: Extensions & ThisType) + => EmberClassConstructor); -interface EmberClass extends EmberClassConstructor { - extend>( - this: EmberClass & Statics, - args?: Extensions & ThisType): EmberClass; +type Reopen = ( + this: new () => Instance, + args?: Extra & ThisType) + => EmberClassConstructor; - extend>( - this: EmberClass & Statics, - mixin1: EmberMixin, - args?: Extensions & ThisType): EmberClass; +type ReopenClass = ( + this: Class, + args?: Extra) + => Class & Extra; - extend>( - this: EmberClass & Statics, - mixin1: EmberMixin, mixin2: EmberMixin, - args?: Extensions & ThisType): EmberClass; +type Detect = ( + this: new () => Instance, + obj: any) + => obj is EmberClassConstructor; - extend>( - this: EmberClass & Statics, - mixin1: EmberMixin, mixin2: EmberMixin, mixin3: EmberMixin, - args?: Extensions & ThisType): EmberClass; +type DetectInstance = ( + this: new () => Instance, + obj: any) + => obj is Instance; - reopen(args?: Extra & ThisType): EmberClass; +interface EmberClassConstructor { + new (...params: any[]): Instance; + create: Create; + createWithMixins: CreateWithMixins; + extend: Extend; - reopenClass(args?: Extra): EmberClass & Extra; + reopen: Reopen; + reopenClass: ReopenClass; - // TODO: remove private API? + detect: Detect; + detectInstance: DetectInstance; - detect(obj: any): obj is EmberClass; - detectInstance(obj: any): obj is T; - /** - Iterate over each computed property for the class, passing its name and any - associated metadata (see metaForProperty) to the callback. - **/ eachComputedProperty(callback: Function, binding: {}): void; - /** - Returns the original hash that was passed to meta(). - @param key property name - **/ metaForProperty(key: string): {}; isClass: boolean; isMethod: boolean; @@ -326,7 +343,7 @@ namespace Ember { An instance of Ember.Application is the starting point for every Ember application. It helps to instantiate, initialize and coordinate the many objects that make up your app. **/ - interface Application extends Namespace { + class Application extends Namespace { /** Call advanceReadiness after any asynchronous setup logic has completed. Each call to deferReadiness must be matched by a call to advanceReadiness @@ -410,7 +427,6 @@ namespace Ember { Router: Router; registry: Registry; } - const Application: EmberClass; /** The `ApplicationInstance` encapsulates all of the stateful aspects of a running `Application`. @@ -440,12 +456,12 @@ namespace Ember { forwarding all requests. This makes it very useful for a number of binding use cases or other cases where being able to swap out the underlying array is useful. **/ - interface ArrayProxy extends Object, MutableArray { + interface ArrayProxy extends MutableArray {} + class ArrayProxy extends Object { content: NativeArray; objectAtContent(idx: number): any; replaceContent(idx: number, amt: number, objects: any[]): void; } - const ArrayProxy: EmberClass; /** AutoLocation will select the best location option based off browser support with the priority order: history, hash, none. **/ @@ -465,17 +481,16 @@ namespace Ember { to(path: string | any[]): Binding; toString(): string; } - interface Button extends Component, TargetActionSupport { + interface Button extends TargetActionSupport {} + class Button extends Component { triggerAction(opts: {}): boolean; } - const Button: EmberClass