diff --git a/types/semantic-ui-popup/global.d.ts b/types/semantic-ui-popup/global.d.ts index 835d196089..f9504e1780 100644 --- a/types/semantic-ui-popup/global.d.ts +++ b/types/semantic-ui-popup/global.d.ts @@ -58,19 +58,66 @@ declare namespace SemanticUI { * Removes popup from the page */ (behavior: 'remove popup'): JQuery; - (behavior: 'setting', name: K, value?: undefined): PopupSettings[K]; - (behavior: 'setting', name: K, value: PopupSettings[K]): JQuery; - (behavior: 'setting', value: PopupSettings.Param): JQuery; - (settings?: PopupSettings.Param): JQuery; + (behavior: 'setting', name: K, value?: undefined): PopupSettings._Impl[K]; + (behavior: 'setting', name: K, value: PopupSettings._Impl[K]): JQuery; + (behavior: 'setting', value: PopupSettings): JQuery; + (settings?: PopupSettings): JQuery; } /** * @see {@link http://semantic-ui.com/modules/popup.html#/settings} */ - interface PopupSettings extends Pick { } + type PopupSettings = PopupSettings.Param; namespace PopupSettings { - type Param = PopupSettings | object; + type Param = (Pick<_Impl, 'popup'> | + Pick<_Impl, 'exclusive'> | + Pick<_Impl, 'movePopup'> | + Pick<_Impl, 'observeChanges'> | + Pick<_Impl, 'boundary'> | + Pick<_Impl, 'context'> | + Pick<_Impl, 'scrollContext'> | + Pick<_Impl, 'jitter'> | + Pick<_Impl, 'position'> | + Pick<_Impl, 'inline'> | + Pick<_Impl, 'preserve'> | + Pick<_Impl, 'prefer'> | + Pick<_Impl, 'lastResort'> | + Pick<_Impl, 'on'> | + Pick<_Impl, 'delay'> | + Pick<_Impl, 'transition'> | + Pick<_Impl, 'duration'> | + Pick<_Impl, 'setFluidWidth'> | + Pick<_Impl, 'hoverable'> | + Pick<_Impl, 'closable'> | + Pick<_Impl, 'addTouchEvents'> | + Pick<_Impl, 'hideOnScroll'> | + Pick<_Impl, 'target'> | + Pick<_Impl, 'distanceAway'> | + Pick<_Impl, 'offset'> | + Pick<_Impl, 'maxSearchDepth'> | + Pick<_Impl, 'onCreate'> | + Pick<_Impl, 'onRemove'> | + Pick<_Impl, 'onShow'> | + Pick<_Impl, 'onVisible'> | + Pick<_Impl, 'onHide'> | + Pick<_Impl, 'onHidden'> | + Pick<_Impl, 'onUnplaceable'> | + Pick<_Impl, 'variation'> | + Pick<_Impl, 'content'> | + Pick<_Impl, 'title'> | + Pick<_Impl, 'html'> | + Pick<_Impl, 'selector'> | + Pick<_Impl, 'metadata'> | + 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 Popup Settings @@ -352,10 +399,12 @@ declare namespace SemanticUI { } namespace Popup { - interface DelaySettings extends Pick { } + type DelaySettings = DelaySettings.Param; namespace DelaySettings { - type Param = DelaySettings | object; + type Param = (Pick<_Impl, 'show'> | + Pick<_Impl, 'hide'>) & + Partial>; interface _Impl { show: number; @@ -363,10 +412,11 @@ declare namespace SemanticUI { } } - interface SelectorSettings extends Pick { } + type SelectorSettings = SelectorSettings.Param; namespace SelectorSettings { - type Param = SelectorSettings | object; + type Param = (Pick<_Impl, 'popup'>) & + Partial>; interface _Impl { /** @@ -376,10 +426,16 @@ declare namespace SemanticUI { } } - interface MetadataSettings extends Pick { } + type MetadataSettings = MetadataSettings.Param; namespace MetadataSettings { - type Param = MetadataSettings | object; + type Param = (Pick<_Impl, 'content'> | + Pick<_Impl, 'html'> | + Pick<_Impl, 'offset'> | + Pick<_Impl, 'position'> | + Pick<_Impl, 'title'> | + Pick<_Impl, 'variation'>) & + Partial>; interface _Impl { /** @@ -409,10 +465,14 @@ declare namespace SemanticUI { } } - interface ClassNameSettings extends Pick { } + type ClassNameSettings = ClassNameSettings.Param; namespace ClassNameSettings { - type Param = ClassNameSettings | object; + type Param = (Pick<_Impl, 'loading'> | + Pick<_Impl, 'popup'> | + Pick<_Impl, 'position'> | + Pick<_Impl, 'visible'>) & + Partial>; interface _Impl { /** @@ -434,10 +494,15 @@ declare namespace SemanticUI { } } - interface ErrorSettings extends Pick { } + type ErrorSettings = ErrorSettings.Param; namespace ErrorSettings { - type Param = ErrorSettings | object; + type Param = (Pick<_Impl, 'invalidPosition'> | + Pick<_Impl, 'cannotPlace'> | + Pick<_Impl, 'method'> | + Pick<_Impl, 'noTransition'> | + Pick<_Impl, 'notFound'>) & + Partial>; interface _Impl { /** diff --git a/types/semantic-ui-popup/semantic-ui-popup-tests.ts b/types/semantic-ui-popup/semantic-ui-popup-tests.ts index b9cda09890..9b00a9dba8 100644 --- a/types/semantic-ui-popup/semantic-ui-popup-tests.ts +++ b/types/semantic-ui-popup/semantic-ui-popup-tests.ts @@ -1,5 +1,5 @@ function test_popup_static() { - $.fn.popup.settings.error.method = 'method'; + $.fn.popup.settings.error!.method = 'method'; $.fn.popup.settings.namespace = 'namespace'; $.fn.popup.settings.name = 'name'; $.fn.popup.settings.silent = false; @@ -10,21 +10,22 @@ function test_popup_static() { function test_popup() { const selector = '.ui.popup'; - $(selector).popup('show') === $(); - $(selector).popup('hide') === $(); - $(selector).popup('hide all') === $(); - $(selector).popup('get popup') === $(); - $(selector).popup('change content', '
') === $(); - $(selector).popup('toggle') === $(); - $(selector).popup('is visible') === true; - $(selector).popup('is hidden') === true; - $(selector).popup('exists') === true; - $(selector).popup('reposition') === $(); - $(selector).popup('set position', 'position') === $(); - $(selector).popup('destroy') === $(); - $(selector).popup('setting', 'debug', undefined) === false; - $(selector).popup('setting', 'debug') === false; - $(selector).popup('setting', 'debug', true) === $(); + $(selector).popup('show'); // $ExpectType JQuery + $(selector).popup('hide'); // $ExpectType JQuery + $(selector).popup('hide all'); // $ExpectType JQuery + $(selector).popup('get popup'); // $ExpectType JQuery + $(selector).popup('change content', '
'); // $ExpectType JQuery + $(selector).popup('toggle'); // $ExpectType JQuery + $(selector).popup('is visible'); // $ExpectType boolean + $(selector).popup('is hidden'); // $ExpectType boolean + $(selector).popup('exists'); // $ExpectType boolean + $(selector).popup('reposition'); // $ExpectType JQuery + $(selector).popup('set position', 'position'); // $ExpectType JQuery + $(selector).popup('destroy'); // $ExpectType JQuery + $(selector).popup('setting', 'debug', undefined); // $ExpectType boolean + $(selector).popup('setting', 'debug'); // $ExpectType boolean + $(selector).popup('setting', 'debug', true); // $ExpectType JQuery + // $ExpectType JQuery $(selector).popup('setting', { namespace: 'namespace', name: 'name', @@ -32,7 +33,8 @@ function test_popup() { debug: true, performance: true, verbose: true - }) === $(); + }); + // $ExpectType JQuery $(selector).popup({ popup: $(), exclusive: true, @@ -64,34 +66,36 @@ function test_popup() { offset: 2, maxSearchDepth: 10, onCreate($module) { - this === $(); - $module === $(); + this; // $ExpectType JQuery + $module; // $ExpectType JQuery }, onRemove($module) { - this === $(); - $module === $(); + this; // $ExpectType JQuery + $module; // $ExpectType JQuery }, onShow($module) { - this === $(); - $module === $(); + this; // $ExpectType JQuery + $module; // $ExpectType JQuery + return false; }, onVisible($module) { - this === $(); - $module === $(); + this; // $ExpectType JQuery + $module; // $ExpectType JQuery }, onHide($module) { - this === $(); - $module === $(); + this; // $ExpectType JQuery + $module; // $ExpectType JQuery + return false; }, onHidden($module) { - this === $(); - $module === $(); + this; // $ExpectType JQuery + $module; // $ExpectType JQuery }, onUnplaceable($module) { - this === $(); - $module === $(); + this; // $ExpectType JQuery + $module; // $ExpectType JQuery }, variation: 'variation', content: 'content', @@ -121,12 +125,16 @@ function test_popup() { noTransition: 'noTransition', notFound: 'notFound' } - }) === $(); - $(selector).popup() === $(); + }); + $(selector).popup(); // $ExpectType JQuery + + $(selector).popup('foo'); // $ExpectError + $(selector).popup({ foo: 'bar' }); // $ExpectError } import popup = require('semantic-ui-popup'); function test_module() { + popup; // $ExpectType Popup $.fn.popup = popup; }