From fb8fc0222624491abfcc4da6101e6d5ac14f3d0a Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Mon, 21 Nov 2022 12:54:40 -0800 Subject: [PATCH 1/2] Correct some public types --- .../@ember/component-test/capabilities.ts | 16 ++++++++ .../component-test/set-component-template.ts | 8 ++++ types/preview/@ember/application/index.d.ts | 12 ------ types/preview/@ember/component/index.d.ts | 39 +++++++++++++++---- 4 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 type-tests/preview/@ember/component-test/capabilities.ts create mode 100644 type-tests/preview/@ember/component-test/set-component-template.ts diff --git a/type-tests/preview/@ember/component-test/capabilities.ts b/type-tests/preview/@ember/component-test/capabilities.ts new file mode 100644 index 00000000000..0014713e0ae --- /dev/null +++ b/type-tests/preview/@ember/component-test/capabilities.ts @@ -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'); diff --git a/type-tests/preview/@ember/component-test/set-component-template.ts b/type-tests/preview/@ember/component-test/set-component-template.ts new file mode 100644 index 00000000000..d416ae6e83c --- /dev/null +++ b/type-tests/preview/@ember/component-test/set-component-template.ts @@ -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(); diff --git a/types/preview/@ember/application/index.d.ts b/types/preview/@ember/application/index.d.ts index d6aed4ade62..1f83001eafc 100644 --- a/types/preview/@ember/application/index.d.ts +++ b/types/preview/@ember/application/index.d.ts @@ -133,16 +133,4 @@ declare module '@ember/application' { * @deprecated Use `import { setOwner } from '@ember/owner';` instead. */ export function setOwner(object: object, 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; } diff --git a/types/preview/@ember/component/index.d.ts b/types/preview/@ember/component/index.d.ts index 01029007bf5..b05b2e0ce96 100644 --- a/types/preview/@ember/component/index.d.ts +++ b/types/preview/@ember/component/index.d.ts @@ -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(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 From cd0e945ef7b0d790d3bbbb0d4a2e217eb586c59f Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Mon, 21 Nov 2022 12:55:27 -0800 Subject: [PATCH 2/2] Correct test file names --- packages/@ember/array/type-tests/{index.ts => index.test.ts} | 0 packages/@ember/array/type-tests/{mutable.ts => mutable.test.ts} | 0 packages/@ember/array/type-tests/{proxy.ts => proxy.test.ts} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename packages/@ember/array/type-tests/{index.ts => index.test.ts} (100%) rename packages/@ember/array/type-tests/{mutable.ts => mutable.test.ts} (100%) rename packages/@ember/array/type-tests/{proxy.ts => proxy.test.ts} (100%) diff --git a/packages/@ember/array/type-tests/index.ts b/packages/@ember/array/type-tests/index.test.ts similarity index 100% rename from packages/@ember/array/type-tests/index.ts rename to packages/@ember/array/type-tests/index.test.ts diff --git a/packages/@ember/array/type-tests/mutable.ts b/packages/@ember/array/type-tests/mutable.test.ts similarity index 100% rename from packages/@ember/array/type-tests/mutable.ts rename to packages/@ember/array/type-tests/mutable.test.ts diff --git a/packages/@ember/array/type-tests/proxy.ts b/packages/@ember/array/type-tests/proxy.test.ts similarity index 100% rename from packages/@ember/array/type-tests/proxy.ts rename to packages/@ember/array/type-tests/proxy.test.ts