feat(store) add overload for projector to inform about incorrect usage#3223
feat(store) add overload for projector to inform about incorrect usage#3223david-shortman wants to merge 1 commit intongrx:masterfrom
Conversation
|
Preview docs changes for 5662d21 at https://previews.ngrx.io/pr3223-5662d219/ |
|
@timdeschryver The docs-app test is failing, seemingly for a reason unrelated to the PR. |
|
@david-shortman 👍 you can leave it as is - we'll take a look at it. |
|
Needs a rebase |
424792e to
b679caa
Compare
|
@brandonroberts The opt-in for strict projectors can take place in two ways: export const selector = createSelector(
selectUrl,
url => url,
{ strict: true } // specify a `strict` flag, which means the developer can allow the Slices and Result to be inferred
);or export const selector = createSelector<[string], string>( // directly supply generic arguments for Slices and Result
selectUrl,
url => url
); |
|
|
||
| export type ProjectorFn<Args extends unknown[], T> = (...args: Args) => T; | ||
|
|
||
| export type StrictMemoizedSelector< |
There was a problem hiding this comment.
this type is not exported from the index so that developers do not create a dependency on this type (presuming it can one day be removed, and all memoized selectors have strict projectors).
instead, if a dev needs to declare the type of a variable, they can use the form MemoizedSelector<State, Result, (slices...Slices) => Result>
cb65036 to
c2ee493
Compare
modules/store/src/selector.ts
Outdated
| > = MemoizedSelector< | ||
| State, | ||
| Result, | ||
| { strict: true } & ((...slices: Slices) => Result) |
There was a problem hiding this comment.
{ strict: true } is purely type information which is used by MemoizedSelector to determine which projector function is used.
There was a problem hiding this comment.
Apparently this is known as an opaque type.
✅ Deploy Preview for ngrx-io canceled.Built without sensitive environment variables
|
f761711 to
be88aaa
Compare
|
closing and reopening with updates once #3354 is merged |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Starts process on #3097
What is the new behavior?
A message on an overload for
projectorwhen it is used incorrectly:Does this PR introduce a breaking change?
Other information