Skip to content
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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
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
62 changes: 31 additions & 31 deletions docs/reference-guides/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _Parameters_
- _state_ `State`: Data state.
- _action_ `string`: Action to check. One of: 'create', 'read', 'update', 'delete'.
- _resource_ `string`: REST resource to check, e.g. 'media' or 'posts'.
- _id_ `GenericRecordKey`: Optional ID of the rest resource to check.
- _id_ `unknown`: Optional ID of the rest resource to check.

_Returns_

Expand All @@ -39,9 +39,9 @@ Calling this may trigger an OPTIONS request to the REST API via the
_Parameters_

- _state_ `State`: Data state.
- _kind_ `Kind`: Entity kind.
- _name_ `Name`: Entity name.
- _recordId_ `GenericRecordKey`: Record's id.
- _kind_ `K`: Entity kind.
- _name_ `N`: Entity name.
Copy link
Member

@dmsnell dmsnell Jun 14, 2022

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>() => 

Copy link
Contributor Author

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

- _recordId_ `KeyOf< K, N >`: Record's id.

_Returns_

Expand Down Expand Up @@ -69,9 +69,9 @@ Returns the autosave for the post and author.
_Parameters_

- _state_ `State`: State tree.
- _postType_ `string`: The type of the parent post.
- _postId_ `GenericRecordKey`: The id of the parent post.
- _authorId_ `GenericRecordKey`: The id of the author.
- _postType_ `Post[ 'type' ]`: The type of the parent post.
- _postId_ `Post[ 'id' ]`: The id of the parent post.
- _authorId_ `User[ 'id' ]`: The id of the author.

_Returns_

Expand All @@ -87,8 +87,8 @@ author for each post.
_Parameters_

- _state_ `State`: State tree.
- _postType_ `string`: The type of the parent post.
- _postId_ `GenericRecordKey`: The id of the parent post.
- _postType_ `Post[ 'type' ]`: The type of the parent post.
- _postId_ `Post[ 'id' ]`: The id of the parent post.

_Returns_

Expand Down Expand Up @@ -128,7 +128,7 @@ _Parameters_

_Returns_

- `any`: The current theme.
- The current theme.

### getCurrentUser

Expand All @@ -155,7 +155,7 @@ _Parameters_

_Returns_

- `EntityRecord | undefined`: The entity record, merged with its edits.
- `EntityRecordOf< K, N > | undefined`: The entity record, merged with its edits.

### getEmbedPreview

Expand Down Expand Up @@ -183,7 +183,7 @@ _Parameters_

_Returns_

- `Array< any >`: Array of entities with config matching kind.
- `AnyEntityConfig[]`: Array of entities with config matching kind.

### getEntitiesConfig

Expand All @@ -196,7 +196,7 @@ _Parameters_

_Returns_

- `Array< any >`: Array of entities with config matching kind.
- `AnyEntityConfig[]`: Array of entities with config matching kind.

### getEntity

Expand All @@ -212,7 +212,7 @@ _Parameters_

_Returns_

- `any`: Entity config
- Entity config

### getEntityConfig

Expand All @@ -226,7 +226,7 @@ _Parameters_

_Returns_

- `any`: Entity config
- `Optional< AnyEntityConfig >`: Entity config

### getEntityRecord

Expand Down Expand Up @@ -259,7 +259,7 @@ _Parameters_

_Returns_

- `Optional< any >`: The entity record's edits.
- `Optional< Partial< EntityRecordOf< K, N > > >`: The entity record's edits.

### getEntityRecordNonTransientEdits

Expand All @@ -278,7 +278,7 @@ _Parameters_

_Returns_

- `Optional< any >`: The entity record's non transient edits.
- `Partial< EntityRecordOf< K, N > >`: The entity record's non transient edits.

### getEntityRecords

Expand All @@ -302,9 +302,9 @@ Returns the specified entity record's last delete error.
_Parameters_

- _state_ `State`: State tree.
- _kind_ `Kind`: Entity kind.
- _name_ `Name`: Entity name.
- _recordId_ `GenericRecordKey`: Record ID.
- _kind_ `K`: Entity kind.
- _name_ `N`: Entity name.
- _recordId_ `KeyOf< K, N >`: Record ID.

_Returns_

Expand All @@ -317,9 +317,9 @@ Returns the specified entity record's last save error.
_Parameters_

- _state_ `State`: State tree.
- _kind_ `Kind`: Entity kind.
- _name_ `Name`: Entity name.
- _recordId_ `GenericRecordKey`: Record ID.
- _kind_ `K`: Entity kind.
- _name_ `N`: Entity name.
- _recordId_ `KeyOf< K, N >`: Record ID.

_Returns_

Expand Down Expand Up @@ -452,8 +452,8 @@ Returns true if the REST request for autosaves has completed.
_Parameters_

- _state_ `State`: State tree.
- _postType_ `string`: The type of the parent post.
- _postId_ `GenericRecordKey`: The id of the parent post.
- _postType_ `Post[ 'type' ]`: The type of the parent post.
- _postId_ `Post[ 'id' ]`: The id of the parent post.

_Returns_

Expand Down Expand Up @@ -492,9 +492,9 @@ Returns true if the specified entity record is autosaving, and false otherwise.
_Parameters_

- _state_ `State`: State tree.
- _kind_ `Kind`: Entity kind.
- _name_ `Name`: Entity name.
- _recordId_ `GenericRecordKey`: Record ID.
- _kind_ `K`: Entity kind.
- _name_ `N`: Entity name.
- _recordId_ `KeyOf< K, N >`: Record ID.

_Returns_

Expand All @@ -507,9 +507,9 @@ Returns true if the specified entity record is deleting, and false otherwise.
_Parameters_

- _state_ `State`: State tree.
- _kind_ `Kind`: Entity kind.
- _name_ `Name`: Entity name.
- _recordId_ `GenericRecordKey`: Record ID.
- _kind_ `K`: Entity kind.
- _name_ `N`: Entity name.
- _recordId_ `KeyOf< K, N >`: Record ID.

_Returns_

Expand Down
62 changes: 31 additions & 31 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ _Parameters_
- _state_ `State`: Data state.
- _action_ `string`: Action to check. One of: 'create', 'read', 'update', 'delete'.
- _resource_ `string`: REST resource to check, e.g. 'media' or 'posts'.
- _id_ `GenericRecordKey`: Optional ID of the rest resource to check.
- _id_ `unknown`: Optional ID of the rest resource to check.

_Returns_

Expand All @@ -286,9 +286,9 @@ Calling this may trigger an OPTIONS request to the REST API via the
_Parameters_

- _state_ `State`: Data state.
- _kind_ `Kind`: Entity kind.
- _name_ `Name`: Entity name.
- _recordId_ `GenericRecordKey`: Record's id.
- _kind_ `K`: Entity kind.
- _name_ `N`: Entity name.
- _recordId_ `KeyOf< K, N >`: Record's id.

_Returns_

Expand Down Expand Up @@ -316,9 +316,9 @@ Returns the autosave for the post and author.
_Parameters_

- _state_ `State`: State tree.
- _postType_ `string`: The type of the parent post.
- _postId_ `GenericRecordKey`: The id of the parent post.
- _authorId_ `GenericRecordKey`: The id of the author.
- _postType_ `Post[ 'type' ]`: The type of the parent post.
- _postId_ `Post[ 'id' ]`: The id of the parent post.
- _authorId_ `User[ 'id' ]`: The id of the author.

_Returns_

Expand All @@ -334,8 +334,8 @@ author for each post.
_Parameters_

- _state_ `State`: State tree.
- _postType_ `string`: The type of the parent post.
- _postId_ `GenericRecordKey`: The id of the parent post.
- _postType_ `Post[ 'type' ]`: The type of the parent post.
- _postId_ `Post[ 'id' ]`: The id of the parent post.

_Returns_

Expand Down Expand Up @@ -375,7 +375,7 @@ _Parameters_

_Returns_

- `any`: The current theme.
- The current theme.

### getCurrentUser

Expand All @@ -402,7 +402,7 @@ _Parameters_

_Returns_

- `EntityRecord | undefined`: The entity record, merged with its edits.
- `EntityRecordOf< K, N > | undefined`: The entity record, merged with its edits.

### getEmbedPreview

Expand Down Expand Up @@ -430,7 +430,7 @@ _Parameters_

_Returns_

- `Array< any >`: Array of entities with config matching kind.
- `AnyEntityConfig[]`: Array of entities with config matching kind.

### getEntitiesConfig

Expand All @@ -443,7 +443,7 @@ _Parameters_

_Returns_

- `Array< any >`: Array of entities with config matching kind.
- `AnyEntityConfig[]`: Array of entities with config matching kind.

### getEntity

Expand All @@ -459,7 +459,7 @@ _Parameters_

_Returns_

- `any`: Entity config
- Entity config

### getEntityConfig

Expand All @@ -473,7 +473,7 @@ _Parameters_

_Returns_

- `any`: Entity config
- `Optional< AnyEntityConfig >`: Entity config

### getEntityRecord

Expand Down Expand Up @@ -506,7 +506,7 @@ _Parameters_

_Returns_

- `Optional< any >`: The entity record's edits.
- `Optional< Partial< EntityRecordOf< K, N > > >`: The entity record's edits.

### getEntityRecordNonTransientEdits

Expand All @@ -525,7 +525,7 @@ _Parameters_

_Returns_

- `Optional< any >`: The entity record's non transient edits.
- `Partial< EntityRecordOf< K, N > >`: The entity record's non transient edits.

### getEntityRecords

Expand All @@ -549,9 +549,9 @@ Returns the specified entity record's last delete error.
_Parameters_

- _state_ `State`: State tree.
- _kind_ `Kind`: Entity kind.
- _name_ `Name`: Entity name.
- _recordId_ `GenericRecordKey`: Record ID.
- _kind_ `K`: Entity kind.
- _name_ `N`: Entity name.
- _recordId_ `KeyOf< K, N >`: Record ID.

_Returns_

Expand All @@ -564,9 +564,9 @@ Returns the specified entity record's last save error.
_Parameters_

- _state_ `State`: State tree.
- _kind_ `Kind`: Entity kind.
- _name_ `Name`: Entity name.
- _recordId_ `GenericRecordKey`: Record ID.
- _kind_ `K`: Entity kind.
- _name_ `N`: Entity name.
- _recordId_ `KeyOf< K, N >`: Record ID.

_Returns_

Expand Down Expand Up @@ -699,8 +699,8 @@ Returns true if the REST request for autosaves has completed.
_Parameters_

- _state_ `State`: State tree.
- _postType_ `string`: The type of the parent post.
- _postId_ `GenericRecordKey`: The id of the parent post.
- _postType_ `Post[ 'type' ]`: The type of the parent post.
- _postId_ `Post[ 'id' ]`: The id of the parent post.

_Returns_

Expand Down Expand Up @@ -739,9 +739,9 @@ Returns true if the specified entity record is autosaving, and false otherwise.
_Parameters_

- _state_ `State`: State tree.
- _kind_ `Kind`: Entity kind.
- _name_ `Name`: Entity name.
- _recordId_ `GenericRecordKey`: Record ID.
- _kind_ `K`: Entity kind.
- _name_ `N`: Entity name.
- _recordId_ `KeyOf< K, N >`: Record ID.

_Returns_

Expand All @@ -754,9 +754,9 @@ Returns true if the specified entity record is deleting, and false otherwise.
_Parameters_

- _state_ `State`: State tree.
- _kind_ `Kind`: Entity kind.
- _name_ `Name`: Entity name.
- _recordId_ `GenericRecordKey`: Record ID.
- _kind_ `K`: Entity kind.
- _name_ `N`: Entity name.
- _recordId_ `KeyOf< K, N >`: Record ID.

_Returns_

Expand Down
Loading