Skip to content

Commit 49bc3cd

Browse files
wagenetkategengler
authored andcommitted
Correct some public types
(cherry picked from commit fb8fc02)
1 parent 26b9d75 commit 49bc3cd

File tree

4 files changed

+56
-21
lines changed

4 files changed

+56
-21
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { capabilities } from '@ember/component';
2+
import { expectTypeOf } from 'expect-type';
3+
4+
expectTypeOf(capabilities('3.13')).toMatchTypeOf<{
5+
asyncLifecycleCallbacks?: boolean | undefined;
6+
destructor?: boolean | undefined;
7+
updateHook?: boolean | undefined;
8+
}>();
9+
10+
capabilities('3.13', { asyncLifecycleCallbacks: true });
11+
capabilities('3.4', { asyncLifecycleCallbacks: true });
12+
13+
// @ts-expect-error invalid capabilities
14+
capabilities('3.13', { asyncLifecycleCallbacks: 1 });
15+
// @ts-expect-error invalid verison
16+
capabilities('3.12');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { setComponentTemplate } from '@ember/component';
2+
import type { TemplateFactory } from 'htmlbars-inline-precompile';
3+
import { expectTypeOf } from 'expect-type';
4+
5+
// Good enough for testing
6+
let factory = {} as TemplateFactory;
7+
8+
expectTypeOf(setComponentTemplate(factory, {})).toEqualTypeOf<object>();

types/preview/@ember/application/index.d.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,5 @@ declare module '@ember/application' {
151151
* `setOwner` forces a new owner on a given object instance. This is primarily
152152
* useful in some testing cases.
153153
*/
154-
export function setOwner(object: unknown, owner: Owner): void;
155-
156-
/**
157-
* Detects when a specific package of Ember (e.g. 'Ember.Application')
158-
* has fully loaded and is available for extension.
159-
*/
160-
export function onLoad(name: string, callback: AnyFn): unknown;
161-
162-
/**
163-
* Called when an Ember.js package (e.g Ember.Application) has finished
164-
* loading. Triggers any callbacks registered for this event.
165-
*/
166-
export function runLoadHooks(name: string, object?: {}): unknown;
154+
export function setOwner(object: object, owner: Owner): void;
167155
}

types/preview/@ember/component/index.d.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,37 @@ declare module '@ember/component' {
106106
object: T
107107
): T;
108108

109-
/**
110-
* Takes a component class and returns the template associated with the given component class,
111-
* if any, or one of its superclasses, if any, or undefined if no template association was found.
112-
*
113-
* @param object the component object
114-
* @return the template factory of the given component
115-
*/
116-
export function getComponentTemplate(obj: object): TemplateFactory | undefined;
109+
/**
110+
* Takes a component class and returns the template associated with the given component class,
111+
* if any, or one of its superclasses, if any, or undefined if no template association was found.
112+
*
113+
* @param object the component object
114+
* @return the template factory of the given component
115+
*/
116+
export function getComponentTemplate(obj: object): TemplateFactory | undefined;
117+
118+
export function setComponentTemplate(factory: TemplateFactory, obj: object): object;
119+
120+
interface ComponentCapabilitiesVersions {
121+
'3.4': {
122+
asyncLifecycleCallbacks?: boolean;
123+
destructor?: boolean;
124+
};
125+
126+
'3.13': {
127+
asyncLifecycleCallbacks?: boolean;
128+
destructor?: boolean;
129+
updateHook?: boolean;
130+
};
131+
}
132+
133+
interface ComponentCapabilities extends Capabilities {
134+
asyncLifeCycleCallbacks: boolean;
135+
destructor: boolean;
136+
updateHook: boolean;
137+
}
138+
139+
export function capabilities<Version extends keyof ComponentCapabilitiesVersions>(managerAPI: Version, options?: ComponentCapabilitiesVersions[Version]): ComponentCapabilities;
117140

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

0 commit comments

Comments
 (0)