diff --git a/packages/client/package.json b/packages/client/package.json index f9458eff..f2fcc894 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -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" }, diff --git a/packages/client/test/typecheck/friendly-types.test-d.ts b/packages/client/test/typecheck/friendly-types.test-d.ts new file mode 100644 index 00000000..221a9902 --- /dev/null +++ b/packages/client/test/typecheck/friendly-types.test-d.ts @@ -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>().toEqualTypeOf<{ + id: string; + attr: string; + }>(); +}); diff --git a/packages/client/tsconfig.test.json b/packages/client/tsconfig.test.json new file mode 100644 index 00000000..0477599e --- /dev/null +++ b/packages/client/tsconfig.test.json @@ -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"] +} diff --git a/packages/client/vitest.config.ts b/packages/client/vitest.config.ts new file mode 100644 index 00000000..da188516 --- /dev/null +++ b/packages/client/vitest.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + typecheck: { + ignoreSourceErrors: false, + tsconfig: './tsconfig.test.json', + }, + }, +});