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

fix(type): only return Promise with delay #491

Merged
merged 3 commits into from Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions package.json
Expand Up @@ -26,7 +26,7 @@
"homepage": "https://github.com/testing-library/user-event#readme",
"files": [
"dist",
"typings"
"typings/index.d.ts"
],
"scripts": {
"build": "kcd-scripts build",
Expand All @@ -35,7 +35,8 @@
"test": "kcd-scripts test",
"test:debug": "kcd-scripts --inspect-brk test --runInBand",
"test:update": "npm test -- --updateSnapshot --coverage",
"validate": "kcd-scripts validate"
"validate": "kcd-scripts validate",
"typecheck": "tsc --project typings"
},
"dependencies": {
"@babel/runtime": "^7.10.2"
Expand All @@ -46,7 +47,8 @@
"@types/estree": "0.0.45",
"is-ci": "^2.0.0",
"jest-serializer-ansi": "^1.0.3",
"kcd-scripts": "^6.2.3"
"kcd-scripts": "^6.2.3",
"typescript": "^4.0.5"
},
"peerDependencies": {
"@testing-library/dom": ">=7.21.4"
Expand Down
6 changes: 3 additions & 3 deletions typings/index.d.ts
Expand Up @@ -53,11 +53,11 @@ declare const userEvent: {
files: FilesArgument,
init?: UploadInitArgument,
) => void
type: (
type: <T extends ITypeOpts>(
element: TargetElement,
text: string,
userOpts?: ITypeOpts,
) => Promise<void>
userOpts?: T,
) => T extends {delay: number} ? Promise<void> : void
tab: (userOpts?: ITabUserOptions) => void
paste: (
element: TargetElement,
Expand Down
8 changes: 8 additions & 0 deletions typings/test.ts
@@ -0,0 +1,8 @@
import userEvent, {TargetElement} from '.'

declare const element: TargetElement
type NotVoid = string | number | boolean | object | null

userEvent.type(element, 'foo', {delay: 1}) as Promise<void>
// @ts-expect-error No delay returns void
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome usage of typescript this was new to me many thanks! ❤️

userEvent.type(element, 'foo') as NotVoid
7 changes: 7 additions & 0 deletions typings/tsconfig.json
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"lib": ["dom"],
"noEmit": true,
"strict": true
}
}