Skip to content

Commit

Permalink
Correct some public types
Browse files Browse the repository at this point in the history
(cherry picked from commit fb8fc02)
  • Loading branch information
wagenet authored and kategengler committed Nov 28, 2022
1 parent 26b9d75 commit 49bc3cd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 21 deletions.
16 changes: 16 additions & 0 deletions type-tests/preview/@ember/component-test/capabilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { capabilities } from '@ember/component';
import { expectTypeOf } from 'expect-type';

expectTypeOf(capabilities('3.13')).toMatchTypeOf<{
asyncLifecycleCallbacks?: boolean | undefined;
destructor?: boolean | undefined;
updateHook?: boolean | undefined;
}>();

capabilities('3.13', { asyncLifecycleCallbacks: true });
capabilities('3.4', { asyncLifecycleCallbacks: true });

// @ts-expect-error invalid capabilities
capabilities('3.13', { asyncLifecycleCallbacks: 1 });
// @ts-expect-error invalid verison
capabilities('3.12');
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { setComponentTemplate } from '@ember/component';
import type { TemplateFactory } from 'htmlbars-inline-precompile';
import { expectTypeOf } from 'expect-type';

// Good enough for testing
let factory = {} as TemplateFactory;

expectTypeOf(setComponentTemplate(factory, {})).toEqualTypeOf<object>();
14 changes: 1 addition & 13 deletions types/preview/@ember/application/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,5 @@ declare module '@ember/application' {
* `setOwner` forces a new owner on a given object instance. This is primarily
* useful in some testing cases.
*/
export function setOwner(object: unknown, owner: Owner): void;

/**
* Detects when a specific package of Ember (e.g. 'Ember.Application')
* has fully loaded and is available for extension.
*/
export function onLoad(name: string, callback: AnyFn): unknown;

/**
* Called when an Ember.js package (e.g Ember.Application) has finished
* loading. Triggers any callbacks registered for this event.
*/
export function runLoadHooks(name: string, object?: {}): unknown;
export function setOwner(object: object, owner: Owner): void;
}
39 changes: 31 additions & 8 deletions types/preview/@ember/component/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,37 @@ declare module '@ember/component' {
object: T
): T;

/**
* Takes a component class and returns the template associated with the given component class,
* if any, or one of its superclasses, if any, or undefined if no template association was found.
*
* @param object the component object
* @return the template factory of the given component
*/
export function getComponentTemplate(obj: object): TemplateFactory | undefined;
/**
* Takes a component class and returns the template associated with the given component class,
* if any, or one of its superclasses, if any, or undefined if no template association was found.
*
* @param object the component object
* @return the template factory of the given component
*/
export function getComponentTemplate(obj: object): TemplateFactory | undefined;

export function setComponentTemplate(factory: TemplateFactory, obj: object): object;

interface ComponentCapabilitiesVersions {
'3.4': {
asyncLifecycleCallbacks?: boolean;
destructor?: boolean;
};

'3.13': {
asyncLifecycleCallbacks?: boolean;
destructor?: boolean;
updateHook?: boolean;
};
}

interface ComponentCapabilities extends Capabilities {
asyncLifeCycleCallbacks: boolean;
destructor: boolean;
updateHook: boolean;
}

export function capabilities<Version extends keyof ComponentCapabilitiesVersions>(managerAPI: Version, options?: ComponentCapabilitiesVersions[Version]): ComponentCapabilities;

// In normal TypeScript, these built-in components are essentially opaque tokens
// that just need to be importable. Declaring them with unique interfaces
Expand Down

0 comments on commit 49bc3cd

Please sign in to comment.