Add types for simulant (#41638)

This commit is contained in:
Elizabeth Craig 2020-01-16 09:14:07 -08:00 committed by Eli Barzilay
parent 970dc8fea8
commit ebc4c80b7d
4 changed files with 55 additions and 0 deletions

14
types/simulant/index.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
// Type definitions for simulant 0.2
// Project: https://github.com/Rich-Harris/simulant#readme
// Definitions by: Elizabeth Craig <https://github.com/ecraig12345>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace event {
function fire(el: Node, e: Event): void;
function fire(el: Node, e: string, payload?: { [key: string]: any }): void;
}
declare function event(eventName: string, payload?: { [key: string]: any }): Event;
declare function event(window: Window, eventName: string, payload?: { [key: string]: any }): Event;
export = event;

View File

@ -0,0 +1,16 @@
import * as simulant from 'simulant';
simulant(window, 'click'); // $ExpectType Event
simulant(window, 'click', { foo: 'bar' }); // $ExpectType Event
simulant('click'); // $ExpectType Event
simulant('click', { foo: 'bar' }); // $ExpectType Event
const div = document.createElement('div');
simulant.fire(document, new MouseEvent('click')); // $ExpectType void
simulant.fire(div, new MouseEvent('click')); // $ExpectType void
simulant.fire(document, 'click'); // $ExpectType void
simulant.fire(div, 'click'); // $ExpectType void
simulant.fire(div, 'click', { foo: 'bar' }); // $ExpectType void

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"simulant-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }