Skip to content

Commit

Permalink
refactor!: Props type N param should extend TypedObject
Browse files Browse the repository at this point in the history
  • Loading branch information
theisel committed Sep 22, 2022
1 parent dec16e8 commit d1b38ea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
17 changes: 17 additions & 0 deletions .changeset/violet-cars-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"astro-portabletext": minor
---

**BREAKING** `Props<N>` type `N` parameter should extend `TypedObject`.

```diff
- import type { Props as $ } from "astro-portabletext/types";
+ import type { Props as $, TypedObject } from "astro-portabletext/types";

- interface Greet {
+ interface Greet extends TypedObject {
greeting: string;
};

export type Props = $<Greet>;
```
18 changes: 8 additions & 10 deletions component/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,11 @@ export type SomePortableTextComponents = Partial<PortableTextComponents>;
*
* @template N Type of Portable Text payload that this component will receive on its `node` property
*/
export interface Props<
N extends TypedObject | Record<string, any> = ArbitraryTypedObject
> {
export interface Props<N extends TypedObject = ArbitraryTypedObject> {
/**
* Portable Text node
*/
node: N extends TypedObject ? N : N & TypedObject;
node: N;
/**
* Index within its parent
*/
Expand All @@ -135,17 +133,17 @@ export interface Props<
* @internal
* @template N Portable Text node type
*/
export type Component<
N extends TypedObject | Record<string, any> = ArbitraryTypedObject
> = (props: Props<N>) => any;
export type Component<N extends TypedObject = ArbitraryTypedObject> = (
props: Props<N>
) => any;

/**
* For internal use
* @internal
*/
export type ComponentOrRecord<
N extends TypedObject | Record<string, any> = ArbitraryTypedObject
> = Component<N> | Record<string, Component<N>>;
export type ComponentOrRecord<N extends TypedObject = ArbitraryTypedObject> =
| Component<N>
| Record<string, Component<N>>;

/**
* Alias to `PortableTextBlock`
Expand Down

0 comments on commit d1b38ea

Please sign in to comment.