Skip to content

Commit

Permalink
fix: TypeScript 5.7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Dec 28, 2024
1 parent 4a2ebe1 commit a0236cb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
26 changes: 26 additions & 0 deletions .changeset/perfect-walls-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@data-client/rest': patch
---

Resource.extend() compatibility with TypeScript 5

Previously [extending existing members](https://dataclient.io/rest/api/resource#extend-override) with no
typed overrides (like [path](https://dataclient.io/rest/api/resource#path)) would not work starting with
TypeScript 5.7.

```ts
const UserResource = UserResourceBase.extend({
partialUpdate: {
getOptimisticResponse(snap, params, body) {
params.id;
params.group;
// @ts-expect-error
params.nothere;
return {
id: params.id,
...body,
};
},
},
});
```
10 changes: 5 additions & 5 deletions packages/rest/src/resourceExtendable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ export interface Extendable<
};
extend<
R extends ResourceInterface,
Get extends PartialRestGenerics = any,
GetList extends PartialRestGenerics = any,
Update extends PartialRestGenerics = any,
PartialUpdate extends PartialRestGenerics = any,
Delete extends PartialRestGenerics = any,
Get extends PartialRestGenerics = {},
GetList extends PartialRestGenerics = {},
Update extends PartialRestGenerics = {},
PartialUpdate extends PartialRestGenerics = {},
Delete extends PartialRestGenerics = {},
>(
this: R,
options: ResourceEndpointExtensions<
Expand Down
10 changes: 5 additions & 5 deletions packages/rest/src/resourceExtensionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export type ExtendedResource<

export interface ResourceEndpointExtensions<
R extends ResourceInterface,
Get extends PartialRestGenerics = any,
GetList extends PartialRestGenerics = any,
Update extends PartialRestGenerics = any,
PartialUpdate extends PartialRestGenerics = any,
Delete extends PartialRestGenerics = any,
Get extends PartialRestGenerics = {},
GetList extends PartialRestGenerics = {},
Update extends PartialRestGenerics = {},
PartialUpdate extends PartialRestGenerics = {},
Delete extends PartialRestGenerics = {},
> {
readonly get?: RestEndpointOptions<
unknown extends Get ? EndpointToFunction<R['get']>
Expand Down

0 comments on commit a0236cb

Please sign in to comment.