diff --git a/types/semantic-ui-dropdown/global.d.ts b/types/semantic-ui-dropdown/global.d.ts index 12425cbace..8fc8c234cd 100644 --- a/types/semantic-ui-dropdown/global.d.ts +++ b/types/semantic-ui-dropdown/global.d.ts @@ -157,19 +157,71 @@ declare namespace SemanticUI { */ (behavior: 'get placeholder text'): string; (behavior: 'destroy'): JQuery; - (behavior: 'setting', name: K, value?: undefined): DropdownSettings[K]; - (behavior: 'setting', name: K, value: DropdownSettings[K]): JQuery; - (behavior: 'setting', value: DropdownSettings.Param): JQuery; - (settings?: DropdownSettings.Param): JQuery; + (behavior: 'setting', name: K, value?: undefined): DropdownSettings._Impl[K]; + (behavior: 'setting', name: K, value: DropdownSettings._Impl[K]): JQuery; + (behavior: 'setting', value: DropdownSettings): JQuery; + (settings?: DropdownSettings): JQuery; } /** * @see {@link http://semantic-ui.com/modules/dropdown.html#/settings} */ - interface DropdownSettings extends Pick { } + type DropdownSettings = DropdownSettings.Param; namespace DropdownSettings { - type Param = DropdownSettings | object; + type Param = (Pick<_Impl, 'on'> | + Pick<_Impl, 'allowReselection'> | + Pick<_Impl, 'allowAdditions'> | + Pick<_Impl, 'hideAdditions'> | + Pick<_Impl, 'action'> | + Pick<_Impl, 'minCharacters'> | + Pick<_Impl, 'match'> | + Pick<_Impl, 'selectOnKeydown'> | + Pick<_Impl, 'forceSelection'> | + Pick<_Impl, 'allowCategorySelection'> | + Pick<_Impl, 'placeholder'> | + Pick<_Impl, 'apiSettings'> | + Pick<_Impl, 'fields'> | + Pick<_Impl, 'saveRemoteData'> | + Pick<_Impl, 'filterRemoteData'> | + Pick<_Impl, 'useLabels'> | + Pick<_Impl, 'maxSelections'> | + Pick<_Impl, 'glyphWidth'> | + Pick<_Impl, 'label'> | + Pick<_Impl, 'direction'> | + Pick<_Impl, 'keepOnScreen'> | + Pick<_Impl, 'context'> | + Pick<_Impl, 'fullTextSearch'> | + Pick<_Impl, 'preserveHTML'> | + Pick<_Impl, 'sortSelect'> | + Pick<_Impl, 'showOnFocus'> | + Pick<_Impl, 'allowTab'> | + Pick<_Impl, 'transition'> | + Pick<_Impl, 'duration'> | + Pick<_Impl, 'keys'> | + Pick<_Impl, 'delay'> | + Pick<_Impl, 'onChange'> | + Pick<_Impl, 'onAdd'> | + Pick<_Impl, 'onRemove'> | + Pick<_Impl, 'onLabelCreate'> | + Pick<_Impl, 'onLabelRemove'> | + Pick<_Impl, 'onLabelSelect'> | + Pick<_Impl, 'onNoResults'> | + Pick<_Impl, 'onShow'> | + Pick<_Impl, 'onHide'> | + Pick<_Impl, 'message'> | + Pick<_Impl, 'selector'> | + Pick<_Impl, 'regExp'> | + 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 Frequently Used Settings @@ -475,10 +527,14 @@ declare namespace SemanticUI { } namespace Dropdown { - interface FieldsSettings extends Pick { } + type FieldsSettings = FieldsSettings.Param; namespace FieldsSettings { - type Param = FieldsSettings | object; + type Param = (Pick<_Impl, 'remoteValues'> | + Pick<_Impl, 'values'> | + Pick<_Impl, 'name'> | + Pick<_Impl, 'value'>) & + Partial>; interface _Impl { /** @@ -508,10 +564,13 @@ declare namespace SemanticUI { } } - interface LabelSettings extends Pick { } + type LabelSettings = LabelSettings.Param; namespace LabelSettings { - type Param = LabelSettings | object; + type Param = (Pick<_Impl, 'transition'> | + Pick<_Impl, 'duration'> | + Pick<_Impl, 'variation'>) & + Partial>; interface _Impl { /** @@ -529,10 +588,21 @@ declare namespace SemanticUI { } } - interface KeySettings extends Pick { } + type KeySettings = KeySettings.Param; namespace KeySettings { - type Param = KeySettings | object; + type Param = (Pick<_Impl, 'backspace'> | + Pick<_Impl, 'delimiter'> | + Pick<_Impl, 'deleteKey'> | + Pick<_Impl, 'enter'> | + Pick<_Impl, 'escape'> | + Pick<_Impl, 'pageUp'> | + Pick<_Impl, 'pageDown'> | + Pick<_Impl, 'leftArrow'> | + Pick<_Impl, 'upArrow'> | + Pick<_Impl, 'rightArrow'> | + Pick<_Impl, 'downArrow'>) & + Partial>; interface _Impl { /** @@ -582,10 +652,14 @@ declare namespace SemanticUI { } } - interface DelaySettings extends Pick { } + type DelaySettings = DelaySettings.Param; namespace DelaySettings { - type Param = DelaySettings | object; + type Param = (Pick<_Impl, 'hide'> | + Pick<_Impl, 'show'> | + Pick<_Impl, 'search'> | + Pick<_Impl, 'touch'>) & + Partial>; interface _Impl { /** @@ -607,10 +681,14 @@ declare namespace SemanticUI { } } - interface MessageSettings extends Pick { } + type MessageSettings = MessageSettings.Param; namespace MessageSettings { - type Param = MessageSettings | object; + type Param = (Pick<_Impl, 'addResult'> | + Pick<_Impl, 'count'> | + Pick<_Impl, 'maxSelections'> | + Pick<_Impl, 'noResults'>) & + Partial>; interface _Impl { /** @@ -632,10 +710,23 @@ declare namespace SemanticUI { } } - interface SelectorSettings extends Pick { } + type SelectorSettings = SelectorSettings.Param; namespace SelectorSettings { - type Param = SelectorSettings | object; + type Param = (Pick<_Impl, 'addition'> | + Pick<_Impl, 'dropdown'> | + Pick<_Impl, 'icon'> | + Pick<_Impl, 'input'> | + Pick<_Impl, 'item'> | + Pick<_Impl, 'label'> | + Pick<_Impl, 'remove'> | + Pick<_Impl, 'siblingLabel'> | + Pick<_Impl, 'menu'> | + Pick<_Impl, 'message'> | + Pick<_Impl, 'menuIcon'> | + Pick<_Impl, 'search'> | + Pick<_Impl, 'text'>) & + Partial>; interface _Impl { /** @@ -693,10 +784,11 @@ declare namespace SemanticUI { } } - interface RegExpSettings extends Pick { } + type RegExpSettings = RegExpSettings.Param; namespace RegExpSettings { - type Param = RegExpSettings | object; + type Param = (Pick<_Impl, 'escape'>) & + Partial>; interface _Impl { /** @@ -706,10 +798,15 @@ declare namespace SemanticUI { } } - interface MetadataSettings extends Pick { } + type MetadataSettings = MetadataSettings.Param; namespace MetadataSettings { - type Param = MetadataSettings | object; + type Param = (Pick<_Impl, 'defaultText'> | + Pick<_Impl, 'defaultValue'> | + Pick<_Impl, 'placeholderText'> | + Pick<_Impl, 'text'> | + Pick<_Impl, 'value'>) & + Partial>; interface _Impl { /** @@ -735,10 +832,29 @@ declare namespace SemanticUI { } } - interface ClassNameSettings extends Pick { } + type ClassNameSettings = ClassNameSettings.Param; namespace ClassNameSettings { - type Param = ClassNameSettings | object; + type Param = (Pick<_Impl, 'active'> | + Pick<_Impl, 'addition'> | + Pick<_Impl, 'animating'> | + Pick<_Impl, 'disabled'> | + Pick<_Impl, 'dropdown'> | + Pick<_Impl, 'filtered'> | + Pick<_Impl, 'hidden'> | + Pick<_Impl, 'item'> | + Pick<_Impl, 'label'> | + Pick<_Impl, 'loading'> | + Pick<_Impl, 'menu'> | + Pick<_Impl, 'message'> | + Pick<_Impl, 'multiple'> | + Pick<_Impl, 'placeholder'> | + Pick<_Impl, 'search'> | + Pick<_Impl, 'selected'> | + Pick<_Impl, 'selection'> | + Pick<_Impl, 'upward'> | + Pick<_Impl, 'visible'>) & + Partial>; interface _Impl { /** @@ -820,10 +936,15 @@ declare namespace SemanticUI { } } - interface ErrorSettings extends Pick { } + type ErrorSettings = ErrorSettings.Param; namespace ErrorSettings { - type Param = ErrorSettings | object; + type Param = (Pick<_Impl, 'action'> | + Pick<_Impl, 'alreadySetup'> | + Pick<_Impl, 'labels'> | + Pick<_Impl, 'method'> | + Pick<_Impl, 'noTransition'>) & + Partial>; interface _Impl { /** diff --git a/types/semantic-ui-dropdown/semantic-ui-dropdown-tests.ts b/types/semantic-ui-dropdown/semantic-ui-dropdown-tests.ts index 2dafbf9c8e..915f96e40f 100644 --- a/types/semantic-ui-dropdown/semantic-ui-dropdown-tests.ts +++ b/types/semantic-ui-dropdown/semantic-ui-dropdown-tests.ts @@ -1,5 +1,5 @@ function test_dropdown_static() { - $.fn.dropdown.settings.error.method = 'method'; + $.fn.dropdown.settings.error!.method = 'method'; $.fn.dropdown.settings.namespace = 'namespace'; $.fn.dropdown.settings.name = 'name'; $.fn.dropdown.settings.silent = false; @@ -10,47 +10,48 @@ function test_dropdown_static() { function test_dropdown() { const selector = '.ui.dropdown'; - $(selector).dropdown('setup menu') === $(); - $(selector).dropdown('refresh') === $(); - $(selector).dropdown('toggle') === $(); - $(selector).dropdown('show') === $(); - $(selector).dropdown('hide') === $(); - $(selector).dropdown('clear') === $(); - $(selector).dropdown('hide others') === $(); - $(selector).dropdown('restore defaults') === $(); - $(selector).dropdown('restore default text') === $(); - $(selector).dropdown('restore placeholder text') === $(); - $(selector).dropdown('restore default value') === $(); - $(selector).dropdown('save defaults') === $(); - $(selector).dropdown('set selected', 123) === $(); - $(selector).dropdown('remove selected', false) === $(); - $(selector).dropdown('set selected', ['456']) === $(); - $(selector).dropdown('set exactly', []) === $(); - $(selector).dropdown('set text', 'hello') === $(); - $(selector).dropdown('set value', 24) === $(); - $(selector).dropdown('get text') === 'text'; - $(selector).dropdown('get value') === {}; - $(selector).dropdown('get item', 'Pennsylvania') === $(); - $(selector).dropdown('bind touch events') === $(); - $(selector).dropdown('bind mouse events') === $(); - $(selector).dropdown('bind intent') === $(); - $(selector).dropdown('unbind intent') === $(); - $(selector).dropdown('determine intent') === true; - $(selector).dropdown('determine select action', 'text', 90) === $(); - $(selector).dropdown('set active') === $(); - $(selector).dropdown('set visible') === $(); - $(selector).dropdown('remove active') === $(); - $(selector).dropdown('remove visible') === $(); - $(selector).dropdown('is selection') === false; - $(selector).dropdown('is animated') === false; - $(selector).dropdown('is visible') === false; - $(selector).dropdown('is hidden') === false; + $(selector).dropdown('setup menu'); // $ExpectType JQuery + $(selector).dropdown('refresh'); // $ExpectType JQuery + $(selector).dropdown('toggle'); // $ExpectType JQuery + $(selector).dropdown('show'); // $ExpectType JQuery + $(selector).dropdown('hide'); // $ExpectType JQuery + $(selector).dropdown('clear'); // $ExpectType JQuery + $(selector).dropdown('hide others'); // $ExpectType JQuery + $(selector).dropdown('restore defaults'); // $ExpectType JQuery + $(selector).dropdown('restore default text'); // $ExpectType JQuery + $(selector).dropdown('restore placeholder text'); // $ExpectType JQuery + $(selector).dropdown('restore default value'); // $ExpectType JQuery + $(selector).dropdown('save defaults'); // $ExpectType JQuery + $(selector).dropdown('set selected', 123); // $ExpectType JQuery + $(selector).dropdown('remove selected', false); // $ExpectType JQuery + $(selector).dropdown('set selected', ['456']); // $ExpectType JQuery + $(selector).dropdown('set exactly', []); // $ExpectType JQuery + $(selector).dropdown('set text', 'hello'); // $ExpectType JQuery + $(selector).dropdown('set value', 24); // $ExpectType JQuery + $(selector).dropdown('get text'); // $ExpectType string + $(selector).dropdown('get value'); // $ExpectType any + $(selector).dropdown('get item', 'Pennsylvania'); // $ExpectType JQuery + $(selector).dropdown('bind touch events'); // $ExpectType JQuery + $(selector).dropdown('bind mouse events'); // $ExpectType JQuery + $(selector).dropdown('bind intent'); // $ExpectType JQuery + $(selector).dropdown('unbind intent'); // $ExpectType JQuery + $(selector).dropdown('determine intent'); // $ExpectType boolean + $(selector).dropdown('determine select action', 'text', 90); // $ExpectType JQuery + $(selector).dropdown('set active'); // $ExpectType JQuery + $(selector).dropdown('set visible'); // $ExpectType JQuery + $(selector).dropdown('remove active'); // $ExpectType JQuery + $(selector).dropdown('remove visible'); // $ExpectType JQuery + $(selector).dropdown('is selection'); // $ExpectType boolean + $(selector).dropdown('is animated'); // $ExpectType boolean + $(selector).dropdown('is visible'); // $ExpectType boolean + $(selector).dropdown('is hidden'); // $ExpectType boolean $(selector).dropdown('get default text') === 'default text'; $(selector).dropdown('get placeholder text') === 'placeholder text'; - $(selector).dropdown('destroy') === $(); - $(selector).dropdown('setting', 'debug', undefined) === false; - $(selector).dropdown('setting', 'debug') === false; - $(selector).dropdown('setting', 'debug', true) === $(); + $(selector).dropdown('destroy'); // $ExpectType JQuery + $(selector).dropdown('setting', 'debug', undefined); // $ExpectType boolean + $(selector).dropdown('setting', 'debug'); // $ExpectType boolean + $(selector).dropdown('setting', 'debug', true); // $ExpectType JQuery + // $ExpectType JQuery $(selector).dropdown('setting', { namespace: 'namespace', name: 'name', @@ -58,19 +59,18 @@ function test_dropdown() { debug: true, performance: true, verbose: true - }) === $(); + }); + // $ExpectType JQuery $(selector).dropdown({ on: 'hover', allowReselection: true, allowAdditions: false, hideAdditions: true, action(text, value, element) { - this === $(); - text === 'text'; - if (typeof value !== 'string') { - value === false; - } - element === $(); + this; // $ExpectType JQuery + text; // $ExpectType string + value; // $ExpectType string | false + element; // $ExpectType JQuery }, minCharacters: 2, match: 'text', @@ -79,9 +79,107 @@ function test_dropdown() { allowCategorySelection: false, placeholder: 'value', apiSettings: { - cache: 'local', + on: 'on', + cache: true, + stateContext: $(), + encodeParameters: false, + defaultData: true, + serializeForm: false, + throttle: 10, throttleFirstRequest: true, - loadingDuration: 20 + interruptRequests: false, + loadingDuration: 3, + hideError: true, + errorDuration: 10, + action: 'action', + url: 'url', + urlData: false, + response: false, + responseAsync(settings, callback) { + settings; // $ExpectType Param + callback; // $ExpectType (response: any) => void + }, + mockResponse: false, + mockResponseAsync(settings, callback) { + settings; // $ExpectType Param + callback; // $ExpectType (response: any) => void + }, + method: 'post', + dataType: 'xml', + data: {}, + beforeSend(settings) { + settings; // $ExpectType Param + }, + beforeXHR(xhrObject) { + xhrObject; // $ExpectType jqXHR + }, + onRequest(promise, xhr) { + promise; // $ExpectType Deferred + xhr; // $ExpectType jqXHR + }, + onResponse(response) { + response; // $ExpectType any + }, + successTest(response) { + response; // $ExpectType any + + return false; + }, + onSuccess(response, element, xhr) { + response; // $ExpectType any + element; // $ExpectType JQuery + xhr; // $ExpectType jqXHR + }, + onComplete(response, element, xhr) { + response; // $ExpectType any + element; // $ExpectType JQuery + xhr; // $ExpectType jqXHR + }, + onFailure(response, element) { + response; // $ExpectType any + element; // $ExpectType JQuery + }, + onError(errorMessage, element, xhr) { + errorMessage; // $ExpectType string + element; // $ExpectType JQuery + xhr; // $ExpectType jqXHR + }, + onAbort(errorMessage, element, xhr) { + errorMessage; // $ExpectType string + element; // $ExpectType JQuery + xhr; // $ExpectType jqXHR + }, + regExp: { + required: /{\$*[A-z0-9]+}/g, + optional: /{\/\$*[A-z0-9]+}/g + }, + selector: { + disabled: '.disabled', + form: 'form' + }, + className: { + loading: 'loading', + error: 'error' + }, + metadata: { + action: 'action', + url: 'url' + }, + error: { + beforeSend: 'beforeSend', + error: 'error', + exitConditions: 'exitConditions', + JSONParse: 'JSONParse', + legacyParameters: 'legacyParameters', + missingAction: 'missingAction', + missingSerialize: 'missingSerialize', + missingURL: 'missingURL', + noReturnedValue: 'noReturnedValue', + parseError: 'parseError', + requiredParameter: 'requiredParameter', + statusMessage: 'statusMessage', + timeout: 'timeout' + } }, fields: { remoteValues: 'remoteValues', @@ -129,14 +227,14 @@ function test_dropdown() { touch: 50 }, onChange(value, text, $choice) { - value === {}; - text === 'text'; - $choice === $(); + value; // $ExpectType any + text; // $ExpectType string + $choice; // $ExpectType JQuery }, onAdd(addedValue, addedText, $addedChoice) { - addedValue === {}; - addedText === 'addedText'; - $addedChoice === $(); + addedValue; // $ExpectType any + addedText; // $ExpectType string + $addedChoice; // $ExpectType JQuery }, message: { addResult: 'addResult', @@ -197,12 +295,16 @@ function test_dropdown() { method: 'method', noTransition: 'noTransition' } - }) === $(); - $(selector).dropdown() === $(); + }); + $(selector).dropdown(); // $ExpectType JQuery + + $(selector).dropdown('foo'); // $ExpectError + $(selector).dropdown({ foo: 'bar' }); // $ExpectError } import dropdown = require('semantic-ui-dropdown'); function test_module() { + dropdown; // $ExpectType Dropdown $.fn.dropdown = dropdown; }