Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(react-query): add tsd #99

Merged
merged 12 commits into from
Nov 9, 2022
532 changes: 532 additions & 0 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
9 changes: 8 additions & 1 deletion packages/react/react-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"name": "@toss/react-query",
"version": "1.0.3",
"types": "./dist/index.d.ts",
"tsd": {
"directory": "./test-d"
},
"sideEffects": false,
"exports": {
".": {
Expand All @@ -12,7 +16,8 @@
"main": "./src/index.ts",
"scripts": {
"build": "rm -rf dist esm && tsc --declaration --emitDeclarationOnly --declarationDir dist && rollup -c rollup.config.js",
"prepack": "yarn build",
"prepack": "yarn build && yarn tsd",
"tsd": "pnpify tsd",
"test": "echo \"no test specified.\"",
"typecheck": "tsc --noEmit"
},
Expand All @@ -23,12 +28,14 @@
"@tossteam/jest": "^17",
"@types/jest": "^28.1.8",
"@types/node": "^14.14.41",
"@yarnpkg/pnpify": "^4.0.0-rc.27",
"babel-jest": "^29",
"concurrently": "^4.1.0",
"jest": "^29.0.1",
"jest-environment-jsdom": "^29",
"react-query": "^3.19.5",
"rollup": "^2.77.0",
"tsd": "^0.24.1",
"typescript": "4.8.3"
},
"peerDependencies": {
Expand Down
13 changes: 13 additions & 0 deletions packages/react/react-query/test-d/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expectType } from 'tsd';
import { SuspendedUseQueryResultOnIdle, SuspendedUseQueryResultOnSuccess, useSuspendedQuery } from '../dist';

const queryKey = ['example'] as const;
const queryFn = async () => 'response';

/* eslint-disable react-hooks/rules-of-hooks */
Copy link
Member Author

@manudeli manudeli Nov 2, 2022

Choose a reason for hiding this comment

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

if no eslint-disable comment, eslint emit error like below. so I added it
image

expectType<SuspendedUseQueryResultOnSuccess<'response'>>(useSuspendedQuery(queryKey, queryFn));
expectType<SuspendedUseQueryResultOnSuccess<'response'>>(useSuspendedQuery(queryKey, queryFn, { enabled: true }));
expectType<SuspendedUseQueryResultOnIdle<undefined>>(useSuspendedQuery(queryKey, queryFn, { enabled: false }));
expectType<SuspendedUseQueryResultOnSuccess<'response'> | SuspendedUseQueryResultOnIdle<undefined>>(
useSuspendedQuery(queryKey, queryFn, { enabled: Boolean(Math.random() > 0.5) })
);
Loading