Skip to content

Commit 9625918

Browse files
committed
Fixed the types
1 parent 3f7d694 commit 9625918

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

ember-primitives/src/service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ const promiseCache = new WeakMap<() => any, unknown>();
6464
* ```js
6565
* import { service } from 'ember-primitives/service';
6666
*
67-
* const loader = () => import('./foo/file/with/class.js');
67+
* const loader = () => {
68+
* let module = await import('./foo/file/with/class.js');
69+
* return () => new module.MyState();
70+
* }
6871
*
6972
* class Demo extends Component {
7073
* state = createAsyncService(this, loader);
@@ -80,7 +83,7 @@ const promiseCache = new WeakMap<() => any, unknown>();
8083
*/
8184
export function createAsyncService<Instance extends object>(
8285
context: object,
83-
theClass: () => Promise<Newable<Instance>> | (() => Promise<() => Instance | Newable<Instance>>)
86+
theClass: () => Promise<Newable<Instance> | (() => Instance)>
8487
): ReturnType<typeof getPromiseState<unknown, Instance>> {
8588
let existing = promiseCache.get(theClass);
8689

test-app/tests/service/create-async-service-test.gts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { setupRenderingTest } from 'ember-qunit';
55

66
import { createAsyncService } from 'ember-primitives/service';
77

8+
import type { Sample } from './sample.ts';
9+
810
module('createAsyncService', function (hooks) {
911
setupRenderingTest(hooks);
1012

@@ -100,7 +102,7 @@ module('createAsyncService', function (hooks) {
100102
});
101103

102104
test('is singleton with await import and new', async function (assert) {
103-
async function factory() {
105+
async function factory(): Promise<() => Sample> {
104106
const module = await import('./sample.ts');
105107

106108
return () => new module.Sample();

0 commit comments

Comments
 (0)