Skip to content

Commit

Permalink
fix(signals): withCalls generate method with no params when strictNul…
Browse files Browse the repository at this point in the history
…lChecks=false

Fix for withCalls to make it generate correct method signature regarless strictNullChecks is true or
false

Fix #82
  • Loading branch information
Gabriel Guerrero authored and gabrielguerrero committed May 23, 2024
1 parent 63a9986 commit 65a5a9e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AsyncPipe } from '@angular/common';
import { Component, inject } from '@angular/core';
import { Component, computed, inject } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatPaginator } from '@angular/material/paginator';
Expand Down Expand Up @@ -33,6 +33,7 @@ import { ProductsShopStore } from '../../products-shop.store';
[list]="store.productsCurrentPage().entities"
[selectedProduct]="store.productsEntitySelected()"
(selectProduct)="select($event)"
[selectedSort]="materialSort()"
(sort)="sort($event)"
/>
<mat-paginator
Expand Down Expand Up @@ -90,6 +91,12 @@ import { ProductsShopStore } from '../../products-shop.store';
export class ProductShopTabComponent {
store = inject(ProductsShopStore);

materialSort = computed(() => {
return {
active: this.store.productsSort().field as keyof Product,
direction: this.store.productsSort().direction,
};
});
select({ id }: Product) {
this.store.selectProductsEntity({ id });
this.store.loadProductDetail({ id });
Expand All @@ -101,7 +108,8 @@ export class ProductShopTabComponent {

sort(sort: Sort<Product>) {
this.store.sortProductsEntities({
sort: { field: sort.active as string, direction: sort.direction },
sort: { field: sort.active, direction: sort.direction },
});
console.log({ sort });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export type ExtractCallResultType<T extends Call | CallConfig> =
: T extends CallConfig<any, infer R>
? R
: never;
export type ExtractCallParams<T extends Call | CallConfig> =
T extends Call<infer P> ? P : T extends CallConfig<infer P> ? P : undefined;

export type NamedCallsStatusComputed<Prop extends string> = {
[K in Prop as `is${Capitalize<string & K>}Loading`]: Signal<boolean>;
Expand Down
31 changes: 19 additions & 12 deletions libs/ngrx-traits/signals/src/lib/with-calls/with-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ import {

import {
CallStatus,
NamedCallStatusComputed,
NamedCallStatusState,
} from '../with-call-status/with-call-status.model';
import { getWithCallStatusKeys } from '../with-call-status/with-call-status.util';
import {
Call,
CallConfig,
ExtractCallParams,
ExtractCallResultType,
NamedCallsStatusComputed,
NamedCallsStatusErrorComputed,
Expand Down Expand Up @@ -127,16 +125,25 @@ export function withCalls<
signals: NamedCallsStatusComputed<keyof Calls & string> &
NamedCallsStatusErrorComputed<Calls>;
methods: {
[K in keyof Calls]: Calls[K] extends (() => any) | CallConfig<undefined>
? { (): void }
: {
(
param:
| ExtractCallParams<Calls[K]>
| Observable<ExtractCallParams<Calls[K]>>
| Signal<ExtractCallParams<Calls[K]>>,
): void;
};
[K in keyof Calls]: Calls[K] extends (...args: infer P) => any
? P extends []
? () => void
: {
(param: P[0]): void;
(param: Observable<P[0]> | Signal<P[0]>): void;
}
: Calls[K] extends CallConfig
? Parameters<Calls[K]['call']> extends undefined[]
? () => void
: {
(...param: Parameters<Calls[K]['call']>): void;
(
param:
| Observable<Parameters<Calls[K]['call']>[0]>
| Signal<Parameters<Calls[K]['call']>[0]>,
): void;
}
: never;
};
}
> {
Expand Down

0 comments on commit 65a5a9e

Please sign in to comment.