Skip to content

Commit a8f34b1

Browse files
committed
chore: make return types explicit
1 parent 7127828 commit a8f34b1

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

packages/model/src/-private/legacy-relationships-support.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type { CollectionRelationship } from '@warp-drive/core-types/cache/relati
2727
import type { LocalRelationshipOperation } from '@warp-drive/core-types/graph';
2828
import type { CollectionResourceRelationship, SingleResourceRelationship } from '@warp-drive/core-types/spec/raw';
2929

30+
import type { ManyArray } from '../-private';
3031
import RelatedCollection from './many-array';
3132
import type { MinimalLegacyRecord } from './model-methods';
3233
import type { BelongsToProxyCreateArgs, BelongsToProxyMeta } from './promise-belongs-to';
@@ -298,11 +299,11 @@ export class LegacySupport {
298299
assert('hasMany only works with the @ember-data/json-api package');
299300
}
300301

301-
reloadHasMany(key: string, options?: BaseFinderOptions) {
302+
reloadHasMany<T>(key: string, options?: BaseFinderOptions): Promise<ManyArray<T>> | PromiseManyArray<T> {
302303
if (HAS_JSON_API_PACKAGE) {
303304
const loadingPromise = this._relationshipPromisesCache[key];
304305
if (loadingPromise) {
305-
return loadingPromise;
306+
return loadingPromise as Promise<ManyArray<T>>;
306307
}
307308
const relationship = this.graph.get(this.identifier, key) as CollectionEdge;
308309
const { definition, state } = relationship;
@@ -313,10 +314,10 @@ export class LegacySupport {
313314
const promise = this.fetchAsyncHasMany(key, relationship, manyArray, options);
314315

315316
if (this._relationshipProxyCache[key]) {
316-
return this._updatePromiseProxyFor('hasMany', key, { promise });
317+
return this._updatePromiseProxyFor('hasMany', key, { promise }) as PromiseManyArray<T>;
317318
}
318319

319-
return promise;
320+
return promise as Promise<ManyArray<T>>;
320321
}
321322
assert(`hasMany only works with the @ember-data/json-api package`);
322323
}
@@ -388,7 +389,9 @@ export class LegacySupport {
388389
return promiseProxy;
389390
}
390391

391-
referenceFor(kind: string | null, name: string) {
392+
referenceFor(kind: 'belongsTo', name: string): BelongsToReference;
393+
referenceFor(kind: 'hasMany', name: string): HasManyReference;
394+
referenceFor(kind: 'belongsTo' | 'hasMany', name: string) {
392395
let reference = this.references[name];
393396

394397
if (!reference) {

packages/model/src/-private/many-array.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,10 @@ export default class RelatedCollection<T = unknown> extends RecordArray<T> {
390390
/**
391391
Reloads all of the records in the manyArray. If the manyArray
392392
holds a relationship that was originally fetched using a links url
393-
Ember Data will revisit the original links url to repopulate the
393+
EmberData will revisit the original links url to repopulate the
394394
relationship.
395395
396-
If the manyArray holds the result of a `store.query()` reload will
396+
If the ManyArray holds the result of a `store.query()` reload will
397397
re-run the original query.
398398
399399
Example
@@ -409,9 +409,9 @@ export default class RelatedCollection<T = unknown> extends RecordArray<T> {
409409
@method reload
410410
@public
411411
*/
412-
reload(options?: BaseFinderOptions) {
412+
reload(options?: BaseFinderOptions): Promise<this> {
413413
// TODO this is odd, we don't ask the store for anything else like this?
414-
return this._manager.reloadHasMany(this.key, options);
414+
return this._manager.reloadHasMany<T>(this.key, options) as Promise<this>;
415415
}
416416

417417
/**

packages/model/src/-private/model-methods.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { RecordStore } from '@warp-drive/core-types/symbols';
1313
import type Errors from './errors';
1414
import { lookupLegacySupport } from './legacy-relationships-support';
1515
import type RecordState from './record-state';
16+
import type BelongsToReference from './references/belongs-to';
17+
import type HasManyReference from './references/has-many';
1618

1719
export interface MinimalLegacyRecord {
1820
errors: Errors;
@@ -51,11 +53,11 @@ export function unloadRecord(this: MinimalLegacyRecord) {
5153
this[RecordStore].unloadRecord(this);
5254
}
5355

54-
export function belongsTo(this: MinimalLegacyRecord, prop: string) {
56+
export function belongsTo(this: MinimalLegacyRecord, prop: string): BelongsToReference {
5557
return lookupLegacySupport(this).referenceFor('belongsTo', prop);
5658
}
5759

58-
export function hasMany(this: MinimalLegacyRecord, prop: string) {
60+
export function hasMany(this: MinimalLegacyRecord, prop: string): HasManyReference {
5961
return lookupLegacySupport(this).referenceFor('hasMany', prop);
6062
}
6163

packages/model/src/-private/references/has-many.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -743,11 +743,11 @@ export default class HasManyReference<
743743
@param {Object} options the options to pass in.
744744
@return {Promise} a promise that resolves with the ManyArray in this has-many relationship.
745745
*/
746-
reload(options?: BaseFinderOptions) {
746+
reload(options?: BaseFinderOptions): Promise<ManyArray<Related>> {
747747
const support: LegacySupport = (LEGACY_SUPPORT as Map<StableRecordIdentifier, LegacySupport>).get(
748748
this.___identifier
749749
)!;
750-
return support.reloadHasMany(this.key, options);
750+
return support.reloadHasMany(this.key, options) as Promise<ManyArray<Related>>;
751751
}
752752
}
753753
defineSignal(HasManyReference.prototype, '_ref', 0);

0 commit comments

Comments
 (0)