Skip to content

Commit

Permalink
fix(type): only return Promise with delay (#491)
Browse files Browse the repository at this point in the history
Co-authored-by: Gerrit Alex <admin@gerritalex.de>
Co-authored-by: Nick McCurdy <nick@nickmccurdy.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
  • Loading branch information
3 people committed Nov 11, 2020
1 parent d1bcda4 commit 2f585fe
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
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
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
}
}

0 comments on commit 2f585fe

Please sign in to comment.