Skip to content

Commit

Permalink
internal: Test TypeScript 4.1, 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Mar 19, 2023
1 parent c0248d6 commit f2981ac
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
7 changes: 4 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ jobs:
- run:
name: typecheck
command: |
yarn run tsc --project examples/todo-app/tsconfig.json
if [ "<< parameters.typescript-version >>" == "latest" ] || [ "<< parameters.typescript-version >>" == "~4.8" ]; then
yarn run tsc --project examples/todo-app/tsconfig.json
yarn run tsc --project examples/github-app/tsconfig.json
fi
yarn run tsc --project examples/todo-app/tsconfig.typetest.json
esmodule-loosenulltypes:
docker: *docker
Expand Down Expand Up @@ -179,8 +180,8 @@ workflows:
# 3.7 is min version for 'full enforcement' (TODO: we need to do a test without rest lib for this to work)
# 4.1 is min version for rest package working
# 4.3 is min version for rest package working well
# TODO: Add back "~4.1", "~4.3", once we can get around linaria types
typescript-version: ["~4.8", "latest"]
# 4.7 (but its broken so we do 4.8) lets you apply a generic type to a function type to see its return value
typescript-version: ["~4.1", "~4.3", "~4.8", "latest"]
requires:
- setup
- esmodule-loosenulltypes:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- 'packages/endpoint/src/schemas/**'
- 'packages/core/**'
- 'examples/benchmark/**'
- '.github/workflows/benchmark.yml'
push:
branches:
- master
Expand All @@ -29,11 +30,14 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Build packages
cache: 'yarn'
- name: Install packages
run: |
npm install -g corepack
corepack enable
yarn install --immutable
- name: Build packages
run: |
NODE_ENV=production BROWSERSLIST_ENV=modern yarn workspaces foreach -ptivR --from @rest-hooks/core run build:lib && NODE_ENV=production BROWSERSLIST_ENV=modern yarn workspaces foreach -ptivR --from @rest-hooks/endpoint run build:lib
- name: Run benchmark
run: yarn workspace example-benchmark build && yarn workspace example-benchmark start | tee output.txt
Expand Down
7 changes: 7 additions & 0 deletions examples/todo-app/tsconfig.typetest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"skipDefaultLibCheck": true,
},
"include": ["typetest.ts"],
}
29 changes: 29 additions & 0 deletions examples/todo-app/typetest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useCache, useController, useSuspense } from '@rest-hooks/react';

import { queryRemaining, TodoResource } from './src/resources/TodoResource';
import { UserResource } from './src/resources/UserResource';

function useTest() {
const ctrl = useController();
const payload = { id: 1, title: '', userId: 1 };
ctrl.fetch(TodoResource.create, payload);

const todos = useSuspense(TodoResource.getList, { userId: 1 });
useSuspense(TodoResource.getList);
todos.map((todo) => {
todo.pk();
todo.title;
ctrl.fetch(
TodoResource.partialUpdate,
{ id: todo.id },
{ completed: true },
);
});

const remaining = useCache(queryRemaining, { userId: 1 });

const users = useSuspense(UserResource.getList);
users.map((user) => {
user.name;
});
}
2 changes: 1 addition & 1 deletion packages/endpoint/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface EndpointInterface<
S extends Schema | undefined = Schema | undefined,
M extends true | undefined = true | undefined,
> extends EndpointExtraOptions<F> {
(...args: Parameters<F>): ReturnType<F>;
(this: ThisParameterType<F>, ...args: Parameters<F>): ReturnType<F>;
key(...args: Parameters<F>): string;
readonly sideEffect?: M;
readonly schema?: S;
Expand Down
2 changes: 1 addition & 1 deletion packages/normalizr/src/endpoint/EndpointInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface EndpointInterface<
S extends Schema | undefined = Schema | undefined,
M extends boolean | undefined = boolean | undefined,
> extends EndpointExtraOptions<F> {
(...args: Parameters<F>): InferReturn<F, S>;
(this: any, ...args: Parameters<F>): InferReturn<F, S>;
key(...args: Parameters<F>): string;
readonly sideEffect?: M;
readonly schema?: S;
Expand Down

1 comment on commit f2981ac

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: f2981ac Previous: c0248d6 Ratio
normalizeLong 324 ops/sec (±1.87%) 293 ops/sec (±0.19%) 0.90
infer All 7340 ops/sec (±0.30%) 5595 ops/sec (±0.24%) 0.76
denormalizeLong 147 ops/sec (±2.00%) 136 ops/sec (±1.07%) 0.93
denormalizeLong with mixin Entity 154 ops/sec (±0.40%) 142 ops/sec (±0.82%) 0.92
denormalizeLong withCache 5500 ops/sec (±1.19%) 4845 ops/sec (±0.87%) 0.88
denormalizeLong All withCache 5707 ops/sec (±0.15%) 4786 ops/sec (±0.11%) 0.84
denormalizeLong Query-sorted withCache 5614 ops/sec (±0.37%) 4816 ops/sec (±0.50%) 0.86
getResponse 5489 ops/sec (±3.55%) 4343 ops/sec (±3.43%) 0.79
getSmallResponse 1892 ops/sec (±3.57%) 1876 ops/sec (±3.15%) 0.99
getSmallInferredResponse 1357 ops/sec (±0.06%) 1570 ops/sec (±0.09%) 1.16
getResponse Query-sorted 531 ops/sec (±0.73%) 461 ops/sec (±1.16%) 0.87
setLong 322 ops/sec (±2.63%) 295 ops/sec (±0.24%) 0.92
setLongWithMerge 131 ops/sec (±0.46%) 123 ops/sec (±0.38%) 0.94
setLongWithSimpleMerge 137 ops/sec (±0.32%) 133 ops/sec (±0.21%) 0.97

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.