-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[TypeScript] More specific core-data selector types #41594
Conversation
540fe09
to
5e389ac
Compare
- _name_ `Name`: Entity name. | ||
- _recordId_ `GenericRecordKey`: Record's id. | ||
- _kind_ `K`: Entity kind. | ||
- _name_ `N`: Entity name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I mentioned having a different name for the public vs. the internal use of function arguments this is one of the reasons why. we like to have short names internally but K
and N
are vague to the outside.
we can solve this in the source files by importing * as …
import { …normalImports } from './entity-types';
import type * as ET from './entity.types';
export const doer<Kind extends ET.Kind, Name extends ET.Name>(…) => …
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I just updated this PR @dmsnell
@@ -192,11 +192,11 @@ Returns the loaded entities for the given kind. | |||
_Parameters_ | |||
|
|||
- _state_ `State`: Data state. | |||
- _kind_ `Kind`: Entity kind. | |||
- _kind_ `ET.Kind`: Entity kind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not ideal that the docs mention both ET.Kind and Kind, but tradeoffs, tradeoffs 🤷
packages/data/README.md
Outdated
@@ -174,11 +174,16 @@ const reduxStore = createStore(); | |||
|
|||
const boundSelectors = mapValues( | |||
existingSelectors, | |||
( selector ) => ( ...args ) => selector( reduxStore.getState(), ...args ) | |||
( selector ) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESLint likes to format code in a different way now and it picked up README.md for some reason
Closing in favor of #42238 |
What?
This PR narrows down
core-data
selectors type signatures after somewhat general ones were introduced as a first step in #41235.Why?
We want to have autocompletion and TypeScript support for core-data primitives as well as compile-time checks, see #39025 for more context.
Testing Instructions
@noisysocks @sirreal @dmsnell @sarayourfriend