Skip to content

Commit

Permalink
internal: Test TypeScript 4.0, 4.1, 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Mar 21, 2023
1 parent a251730 commit d06b950
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
12 changes: 7 additions & 5 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 @@ -177,10 +178,11 @@ workflows:
matrix:
parameters:
# 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.0 is min version for rest package working
# 4.1 is min version for rest package working well
# 4.3
# 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.0", "~4.1", "~4.3", "~4.8", "latest"]
requires:
- setup
- esmodule-loosenulltypes:
Expand Down
8 changes: 6 additions & 2 deletions .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 @@ -23,17 +24,20 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2-beta
- uses: actions/checkout@v3
with:
fetch-depth: 1
- 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
12 changes: 8 additions & 4 deletions examples/todo-app/src/resources/TodoResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ export const TodoResource = {
},
}),
create: TodoResourceBase.create.extend({
searchParams: {} as { userId?: string | number } | undefined,
getOptimisticResponse(snap, body) {
return body;
},
update: (newResourceId: string, urlParams) => ({
[TodoResourceBase.getList.key({ userId: urlParams?.userId })]: (
resourceIds: string[] = [],
) => [...resourceIds, newResourceId],
update: (
newResourceId: string,
urlParams?: { userId?: string | number },
) => ({
[TodoResourceBase.getList.key(
urlParams?.userId ? { userId: urlParams?.userId } : undefined,
)]: (resourceIds: string[] = []) => [...resourceIds, newResourceId],
}),
}),
delete: TodoResourceBase.delete.extend({
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;
});
}

1 comment on commit d06b950

@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: d06b950 Previous: c0248d6 Ratio
normalizeLong 288 ops/sec (±0.15%) 293 ops/sec (±0.19%) 1.02
infer All 5505 ops/sec (±0.29%) 5595 ops/sec (±0.24%) 1.02
denormalizeLong 130 ops/sec (±1.38%) 136 ops/sec (±1.07%) 1.05
denormalizeLong with mixin Entity 140 ops/sec (±0.82%) 142 ops/sec (±0.82%) 1.01
denormalizeLong withCache 4063 ops/sec (±1.73%) 4845 ops/sec (±0.87%) 1.19
denormalizeLong All withCache 4756 ops/sec (±0.09%) 4786 ops/sec (±0.11%) 1.01
denormalizeLong Query-sorted withCache 4745 ops/sec (±0.56%) 4816 ops/sec (±0.50%) 1.01
getResponse 4309 ops/sec (±3.43%) 4343 ops/sec (±3.43%) 1.01
getSmallResponse 1843 ops/sec (±3.06%) 1876 ops/sec (±3.15%) 1.02
getSmallInferredResponse 1691 ops/sec (±0.12%) 1570 ops/sec (±0.09%) 0.93
getResponse Query-sorted 455 ops/sec (±1.60%) 461 ops/sec (±1.16%) 1.01
setLong 286 ops/sec (±0.10%) 295 ops/sec (±0.24%) 1.03
setLongWithMerge 119 ops/sec (±0.45%) 123 ops/sec (±0.38%) 1.03
setLongWithSimpleMerge 129 ops/sec (±0.29%) 133 ops/sec (±0.21%) 1.03

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

Please sign in to comment.