Skip to content

Commit

Permalink
add client typecheck, add test for Entity type
Browse files Browse the repository at this point in the history
  • Loading branch information
wernst committed Jun 12, 2024
1 parent ac428fe commit 3dd087e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"build:watch": "tsc -w",
"lint:build": "npx publint",
"lint": "tsc --noEmit",
"test": "vitest run",
"test": "yarn test:unit && yarn typecheck",
"test:unit": "vitest run",
"typecheck": "vitest --typecheck.only --no-watch",
"publish-pkg": "node ../../scripts/npm-check-version-and-publish.js",
"build-worker": "esbuild ./src/worker-client-operator.ts --bundle --minify --platform=browser --outfile=./dist/worker-client-operator.js --format=esm --sourcemap"
},
Expand Down
25 changes: 25 additions & 0 deletions packages/client/test/typecheck/friendly-types.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expectTypeOf, test } from 'vitest';
import { Schema as S } from '@triplit/db';
import { Entity } from '../../src/utils/query';

test('Entity', () => {
const schema = {
a: {
schema: S.Schema({
id: S.Id(),
attr: S.String(),
rel: S.RelationById('b', '$bId'),
}),
},
b: {
schema: S.Schema({
id: S.Id(),
attr: S.String(),
}),
},
};
expectTypeOf<Entity<typeof schema, 'a'>>().toEqualTypeOf<{
id: string;
attr: string;
}>();
});
18 changes: 18 additions & 0 deletions packages/client/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// TODO: combine with tsconfigs
{
"compilerOptions": {
"lib": ["ESNext"],
"target": "ESNext", // You can adjust the target as needed.
"module": "ESNext", // This will be overridden in npm scripts
"moduleResolution": "node",
"strict": true,
"resolveJsonModule": true,
"isolatedModules": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true,
"useDefineForClassFields": true
},
"include": ["./test/**/*.test-d.ts"]
}
10 changes: 10 additions & 0 deletions packages/client/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
typecheck: {
ignoreSourceErrors: false,
tsconfig: './tsconfig.test.json',
},
},
});

0 comments on commit 3dd087e

Please sign in to comment.