diff --git a/types/semantic-ui-modal/global.d.ts b/types/semantic-ui-modal/global.d.ts index 84f9116e8b..2e6efc4e1d 100644 --- a/types/semantic-ui-modal/global.d.ts +++ b/types/semantic-ui-modal/global.d.ts @@ -56,19 +56,46 @@ declare namespace SemanticUI { (behavior: 'set active'): JQuery; (behavior: 'attach events', selector: string | JQuery, event?: string): JQuery; (behavior: 'destroy'): JQuery; - (behavior: 'setting', name: K, value?: undefined): ModalSettings[K]; - (behavior: 'setting', name: K, value: ModalSettings[K]): JQuery; - (behavior: 'setting', value: ModalSettings.Param): JQuery; - (settings?: ModalSettings.Param): JQuery; + (behavior: 'setting', name: K, value?: undefined): ModalSettings._Impl[K]; + (behavior: 'setting', name: K, value: ModalSettings._Impl[K]): JQuery; + (behavior: 'setting', value: ModalSettings): JQuery; + (settings?: ModalSettings): JQuery; } /** * @see {@link http://semantic-ui.com/modules/modal.html#/settings} */ - interface ModalSettings extends Pick { } + type ModalSettings = ModalSettings.Param; namespace ModalSettings { - type Param = ModalSettings | object; + type Param = (Pick<_Impl, 'detachable'> | + Pick<_Impl, 'autofocus'> | + Pick<_Impl, 'observeChanges'> | + Pick<_Impl, 'allowMultiple'> | + Pick<_Impl, 'keyboardShortcuts'> | + Pick<_Impl, 'offset'> | + Pick<_Impl, 'context'> | + Pick<_Impl, 'closable'> | + Pick<_Impl, 'dimmerSettings'> | + Pick<_Impl, 'transition'> | + Pick<_Impl, 'duration'> | + Pick<_Impl, 'queue'> | + Pick<_Impl, 'onShow'> | + Pick<_Impl, 'onVisible'> | + Pick<_Impl, 'onHide'> | + Pick<_Impl, 'onHidden'> | + Pick<_Impl, 'onApprove'> | + Pick<_Impl, 'onDeny'> | + Pick<_Impl, 'selector'> | + Pick<_Impl, 'className'> | + Pick<_Impl, 'error'> | + Pick<_Impl, 'namespace'> | + Pick<_Impl, 'name'> | + Pick<_Impl, 'silent'> | + Pick<_Impl, 'debug'> | + Pick<_Impl, 'performance'> | + Pick<_Impl, 'verbose'>) & + Partial>; interface _Impl { // region Modal Settings @@ -232,10 +259,13 @@ declare namespace SemanticUI { } namespace Modal { - interface SelectorSettings extends Pick { } + type SelectorSettings = SelectorSettings.Param; namespace SelectorSettings { - type Param = SelectorSettings | object; + type Param = (Pick<_Impl, 'close'> | + Pick<_Impl, 'approve'> | + Pick<_Impl, 'deny'>) & + Partial>; interface _Impl { /** @@ -253,10 +283,12 @@ declare namespace SemanticUI { } } - interface ClassNameSettings extends Pick { } + type ClassNameSettings = ClassNameSettings.Param; namespace ClassNameSettings { - type Param = ClassNameSettings | object; + type Param = (Pick<_Impl, 'active'> | + Pick<_Impl, 'scrolling'>) & + Partial>; interface _Impl { /** @@ -270,10 +302,11 @@ declare namespace SemanticUI { } } - interface ErrorSettings extends Pick { } + type ErrorSettings = ErrorSettings.Param; namespace ErrorSettings { - type Param = ErrorSettings | object; + type Param = (Pick<_Impl, 'method'>) & + Partial>; interface _Impl { /** diff --git a/types/semantic-ui-modal/semantic-ui-modal-tests.ts b/types/semantic-ui-modal/semantic-ui-modal-tests.ts index ed2a10d3e2..422b5de2e6 100644 --- a/types/semantic-ui-modal/semantic-ui-modal-tests.ts +++ b/types/semantic-ui-modal/semantic-ui-modal-tests.ts @@ -1,5 +1,5 @@ function test_modal_static() { - $.fn.modal.settings.error.method = 'method'; + $.fn.modal.settings.error!.method = 'method'; $.fn.modal.settings.namespace = 'namespace'; $.fn.modal.settings.name = 'name'; $.fn.modal.settings.silent = false; @@ -10,23 +10,24 @@ function test_modal_static() { function test_modal() { const selector = '.ui.modal'; - $(selector).modal('show') === $(); - $(selector).modal('hide') === $(); - $(selector).modal('toggle') === $(); - $(selector).modal('refresh') === $(); - $(selector).modal('show dimmer') === $(); - $(selector).modal('hide dimmer') === $(); - $(selector).modal('hide others') === $(); - $(selector).modal('hide all') === $(); - $(selector).modal('cache sizes') === $(); - $(selector).modal('can fit') === true; - $(selector).modal('is active') === true; - $(selector).modal('set active') === $(); - $(selector).modal('attach events', 'selector', 'blur') === $(); - $(selector).modal('destroy') === $(); - $(selector).modal('setting', 'debug', undefined) === false; - $(selector).modal('setting', 'debug') === false; - $(selector).modal('setting', 'debug', true) === $(); + $(selector).modal('show'); // $ExpectType JQuery + $(selector).modal('hide'); // $ExpectType JQuery + $(selector).modal('toggle'); // $ExpectType JQuery + $(selector).modal('refresh'); // $ExpectType JQuery + $(selector).modal('show dimmer'); // $ExpectType JQuery + $(selector).modal('hide dimmer'); // $ExpectType JQuery + $(selector).modal('hide others'); // $ExpectType JQuery + $(selector).modal('hide all'); // $ExpectType JQuery + $(selector).modal('cache sizes'); // $ExpectType JQuery + $(selector).modal('can fit'); // $ExpectType boolean + $(selector).modal('is active'); // $ExpectType boolean + $(selector).modal('set active'); // $ExpectType JQuery + $(selector).modal('attach events', 'selector', 'blur'); // $ExpectType JQuery + $(selector).modal('destroy'); // $ExpectType JQuery + $(selector).modal('setting', 'debug', undefined); // $ExpectType boolean + $(selector).modal('setting', 'debug'); // $ExpectType boolean + $(selector).modal('setting', 'debug', true); // $ExpectType JQuery + // $ExpectType JQuery $(selector).modal('setting', { namespace: 'namespace', name: 'name', @@ -34,7 +35,8 @@ function test_modal() { debug: true, performance: true, verbose: true - }) === $(); + }); + // $ExpectType JQuery $(selector).modal({ detachable: true, autofocus: false, @@ -57,13 +59,13 @@ function test_modal() { }, transition: 'fade', onShow() { - this === $(); + this; // $ExpectType JQuery }, onHide() { - this === $(); + this; // $ExpectType JQuery }, onChange() { - this === $(); + this; // $ExpectType JQuery }, selector: { dimmable: '.dimmable', @@ -93,27 +95,30 @@ function test_modal() { duration: 400, queue: true, onShow() { - this === $(); + this; // $ExpectType JQuery }, onVisible() { - this === $(); + this; // $ExpectType JQuery }, onHide($element) { - this === $(); - $element === $(); + this; // $ExpectType JQuery + $element; // $ExpectType JQuery + return false; }, onHidden() { - this === $(); + this; // $ExpectType JQuery }, onApprove($element) { - this === $(); - $element === $(); + this; // $ExpectType JQuery + $element; // $ExpectType JQuery + return false; }, onDeny($element) { - this === $(); - $element === $(); + this; // $ExpectType JQuery + $element; // $ExpectType JQuery + return false; }, selector: { @@ -128,12 +133,16 @@ function test_modal() { error: { method: 'method' } - }) === $(); - $(selector).modal() === $(); + }); + $(selector).modal(); // $ExpectType JQuery + + $(selector).modal('foo'); // $ExpectError + $(selector).modal({ foo: 'bar' }); // $ExpectError } import modal = require('semantic-ui-modal'); function test_module() { + modal; // $ExpectType Modal $.fn.modal = modal; }