Skip to content

feat: better types for legacy store methods #9387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup lint
  • Loading branch information
runspired committed Apr 30, 2024
commit 0c98b86644152801bbcbf288008e610e3dea0caf
6 changes: 4 additions & 2 deletions packages/model/src/-private/references/belongs-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { defineSignal } from '@ember-data/tracking/-private';
import { DEBUG } from '@warp-drive/build-config/env';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import type { StableExistingRecordIdentifier } from '@warp-drive/core-types/identifier';
import type { TypeFromInstanceOrString } from '@warp-drive/core-types/record';
import type { TypeFromInstance, TypeFromInstanceOrString } from '@warp-drive/core-types/record';
import type {
LinkObject,
Links,
Expand Down Expand Up @@ -328,7 +328,9 @@ export default class BelongsToReference<
_resource() {
this._ref; // subscribe
const cache = this.store.cache;
return cache.getRelationship(this.___identifier, this.key) as SingleResourceRelationship;
return cache.getRelationship(this.___identifier, this.key) as SingleResourceRelationship<
StableRecordIdentifier<TypeFromInstance<Related>>
>;
}

/**
Expand Down
20 changes: 11 additions & 9 deletions packages/store/src/-private/store-service.type-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ResourceType } from '@warp-drive/core-types/symbols';
import Store from './store-service';
import { expectTypeOf } from 'expect-type';
import { IdentifierArray } from '../-private';
import { Collection } from './record-arrays/identifier-array';

import type { ResourceType } from '@warp-drive/core-types/symbols';

import type { IdentifierArray } from '../-private';
import type { Collection } from './record-arrays/identifier-array';
import Store from './store-service';

//////////////////////////////////
//////////////////////////////////
Expand Down Expand Up @@ -221,7 +223,7 @@ import { Collection } from './record-arrays/identifier-array';
[ResourceType]: 'user';
};

expectTypeOf(store.findAll('user')).toEqualTypeOf<Promise<IdentifierArray<unknown>>>();
expectTypeOf(store.findAll('user')).toEqualTypeOf<Promise<IdentifierArray>>();
expectTypeOf(
// @ts-expect-error no matching signature since no brand from which to check 'user'
store.findAll<UnbrandedUser>('user')
Expand Down Expand Up @@ -274,7 +276,7 @@ import { Collection } from './record-arrays/identifier-array';
],
});

expectTypeOf<IdentifierArray<unknown>>(result);
expectTypeOf<IdentifierArray>(result);
expectTypeOf<IdentifierArray<MyThing>>(result2);
}

Expand All @@ -297,7 +299,7 @@ import { Collection } from './record-arrays/identifier-array';
// @ts-expect-error expect error since no second argument
void store.query('user');

expectTypeOf(store.query('user', {})).toEqualTypeOf<Promise<Collection<unknown>>>();
expectTypeOf(store.query('user', {})).toEqualTypeOf<Promise<Collection>>();
expectTypeOf(
// @ts-expect-error no matching signature since no brand from which to check 'user'
store.query<UnbrandedUser>('user', {})
Expand Down Expand Up @@ -365,7 +367,7 @@ import { Collection } from './record-arrays/identifier-array';
],
});

expectTypeOf<Collection<unknown>>(result);
expectTypeOf<Collection<unknown>>(result3);
expectTypeOf<Collection>(result);
expectTypeOf<Collection>(result3);
expectTypeOf<Collection<MyThing>>(result2);
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy