mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 Merge PR #45869 d3-dispatch - parameter that need not be an EventTarget by @kum-deepak
* Add example from https://github.com/d3/d3-dispatch as a test case - this uses a very simple object as `that` which is not an `EventTarget`. * Relax template parameter - it need not be an `EventTarget`. * Relax template parameter to be any object - it need not be an `EventTarget`.
This commit is contained in:
parent
1d8c0f9575
commit
4b4a22db04
@ -15,7 +15,12 @@ interface Datum {
|
||||
b: string;
|
||||
}
|
||||
|
||||
interface ContextObject {
|
||||
about: string;
|
||||
}
|
||||
|
||||
let dispatch: d3Dispatch.Dispatch<HTMLElement>;
|
||||
let dispatch2: d3Dispatch.Dispatch<ContextObject>;
|
||||
let callback: (this: HTMLElement, ...args: any[]) => void;
|
||||
let callbackOrUndef: ((this: HTMLElement, ...args: any[]) => void) | undefined;
|
||||
let undef: undefined;
|
||||
@ -24,6 +29,7 @@ let undef: undefined;
|
||||
|
||||
// create new dispatch object
|
||||
dispatch = d3Dispatch.dispatch('foo', 'bar');
|
||||
dispatch2 = d3Dispatch.dispatch('start', 'end');
|
||||
|
||||
function cbFn(this: HTMLElement, d: Datum, i: number) {
|
||||
console.log(this.baseURI ? this.baseURI : 'nada');
|
||||
@ -50,6 +56,8 @@ dispatch.call('foo');
|
||||
dispatch.call('foo', document.body);
|
||||
dispatch.call('foo', document.body, { a: 3, b: 'test' }, 1);
|
||||
|
||||
dispatch2.call('start', {about: 'I am a context object'}, 'I am an argument');
|
||||
|
||||
dispatch.apply('bar');
|
||||
dispatch.apply('bar', document.body);
|
||||
dispatch.apply('bar', document.body, [{ a: 3, b: 'test' }, 1]);
|
||||
|
||||
4
types/d3-dispatch/index.d.ts
vendored
4
types/d3-dispatch/index.d.ts
vendored
@ -8,7 +8,7 @@
|
||||
|
||||
// Last module patch version validated against: 1.0.3
|
||||
|
||||
export interface Dispatch<T extends EventTarget> {
|
||||
export interface Dispatch<T extends object> {
|
||||
/**
|
||||
* Like `function.apply`, invokes each registered callback for the specified type,
|
||||
* passing the callback the specified arguments, with `that` as the `this` context.
|
||||
@ -71,4 +71,4 @@ export interface Dispatch<T extends EventTarget> {
|
||||
* @param types The event types.
|
||||
* @throws "illegal type" on empty string or duplicated event types.
|
||||
*/
|
||||
export function dispatch<T extends EventTarget>(...types: string[]): Dispatch<T>;
|
||||
export function dispatch<T extends object>(...types: string[]): Dispatch<T>;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user