Skip to content

Commit

Permalink
Do not publish the data types
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Feb 22, 2022
1 parent 2ce3ce0 commit dde0888
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
1 change: 0 additions & 1 deletion packages/core-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"main": "build/index.js",
"module": "build-module/index.js",
"react-native": "src/index",
"types": "src/types/index.ts",
"sideEffects": [
"{src,build,build-module}/index.js"
],
Expand Down
45 changes: 0 additions & 45 deletions packages/core-data/src/types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,48 +191,3 @@ const updatablePost = {} as Updatable< Post >;
A string that the server renders which often involves modifications from the raw source string.

For example, block HTML with the comment delimiters exists in `post_content` but those comments are stripped out when rendering to a page view. Similarly, plugins might modify content or replace shortcodes.

## Extending

You can extend the entity record definitions using [TypeScript's declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html).

For example, if you're building a plugin that displays a number of views of each comment, you can add a new `numberOfViews` field to the `Comment` type like this:

```ts
// In core-data
export namespace WPBaseTypes {
// This is the parent interface – it can be extended
export interface Comment< C extends Context > {
id: number;
// ...
}
}

// This the child type used in function signatures – it cannot be extended
export type Comment< C extends Context > = OmitNevers<
WPBaseTypes.Comment< C >
>;

// In the plugin
import type { Context } from '@wordpress/core-data';
// Target the core-data module
declare module '@wordpress/core-data' {
// Extend the WPBaseTypes namespace through declaration merging
export namespace WPBaseTypes {
// Extend the parent Commet interface through declaration merging
export interface Comment< C extends Context > {
numberOfViews: number;
}
}
}

import type { Comment } from '@wordpress/core-data';
// Create an instance of the child type
const c : Comment< 'view' > = ...;

// Extending the parent had the desired effect on the child type:
// c.numberOfViews is a number
// c.id is still present
```

Of course, you will also need to extend the REST API to expose the numberOfViews property.

0 comments on commit dde0888

Please sign in to comment.