diff --git a/types/semantic-ui-search/global.d.ts b/types/semantic-ui-search/global.d.ts index bb3df65035..d5d265a4af 100644 --- a/types/semantic-ui-search/global.d.ts +++ b/types/semantic-ui-search/global.d.ts @@ -94,19 +94,52 @@ declare namespace SemanticUI { * Removes all events */ (behavior: 'destroy'): JQuery; - (behavior: 'setting', name: K, value?: undefined): SearchSettings[K]; - (behavior: 'setting', name: K, value: SearchSettings[K]): JQuery; - (behavior: 'setting', value: SearchSettings.Param): JQuery; - (settings?: SearchSettings.Param): JQuery; + (behavior: 'setting', name: K, value?: undefined): SearchSettings._Impl[K]; + (behavior: 'setting', name: K, value: SearchSettings._Impl[K]): JQuery; + (behavior: 'setting', value: SearchSettings): JQuery; + (settings?: SearchSettings): JQuery; } /** * @see {@link http://semantic-ui.com/modules/search.html#/settings} */ - interface SearchSettings extends Pick { } + type SearchSettings = SearchSettings.Param; namespace SearchSettings { - type Param = SearchSettings | object; + type Param = (Pick<_Impl, 'apiSettings'> | + Pick<_Impl, 'minCharacters'> | + Pick<_Impl, 'transition'> | + Pick<_Impl, 'duration'> | + Pick<_Impl, 'maxResults'> | + Pick<_Impl, 'cache'> | + Pick<_Impl, 'source'> | + Pick<_Impl, 'selectFirstResult'> | + Pick<_Impl, 'showNoResults'> | + Pick<_Impl, 'searchFullText'> | + Pick<_Impl, 'fields'> | + Pick<_Impl, 'searchFields'> | + Pick<_Impl, 'hideDelay'> | + Pick<_Impl, 'searchDelay'> | + Pick<_Impl, 'easing'> | + Pick<_Impl, 'onSelect'> | + Pick<_Impl, 'onResultsAdd'> | + Pick<_Impl, 'onSearchQuery'> | + Pick<_Impl, 'onResults'> | + Pick<_Impl, 'onResultsOpen'> | + Pick<_Impl, 'onResultsClose'> | + Pick<_Impl, 'templates'> | + Pick<_Impl, 'regExp'> | + 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 Behavior @@ -306,10 +339,21 @@ declare namespace SemanticUI { } namespace Search { - interface FieldsSettings extends Pick { } + type FieldsSettings = FieldsSettings.Param; namespace FieldsSettings { - type Param = FieldsSettings | object; + type Param = (Pick<_Impl, 'categories'> | + Pick<_Impl, 'categoryName'> | + Pick<_Impl, 'categoryResults'> | + Pick<_Impl, 'description'> | + Pick<_Impl, 'image'> | + Pick<_Impl, 'price'> | + Pick<_Impl, 'results'> | + Pick<_Impl, 'title'> | + Pick<_Impl, 'action'> | + Pick<_Impl, 'actionText'> | + Pick<_Impl, 'actionURL'>) & + Partial>; interface _Impl { /** @@ -381,10 +425,14 @@ declare namespace SemanticUI { } } - interface TemplatesSettings extends Pick { } + type TemplatesSettings = TemplatesSettings.Param; namespace TemplatesSettings { - type Param = TemplatesSettings | object; + type Param = (Pick<_Impl, 'escape'> | + Pick<_Impl, 'message'> | + Pick<_Impl, 'category'> | + Pick<_Impl, 'standard'>) & + Partial>; interface _Impl { escape(string: string): string; @@ -394,10 +442,12 @@ declare namespace SemanticUI { } } - interface RegExpSettings extends Pick { } + type RegExpSettings = RegExpSettings.Param; namespace RegExpSettings { - type Param = RegExpSettings | object; + type Param = (Pick<_Impl, 'escape'> | + Pick<_Impl, 'beginsWith'>) & + Partial>; interface _Impl { /** @@ -411,10 +461,15 @@ declare namespace SemanticUI { } } - interface SelectorSettings extends Pick { } + type SelectorSettings = SelectorSettings.Param; namespace SelectorSettings { - type Param = SelectorSettings | object; + type Param = (Pick<_Impl, 'prompt'> | + Pick<_Impl, 'searchButton'> | + Pick<_Impl, 'results'> | + Pick<_Impl, 'category'> | + Pick<_Impl, 'result'>) & + Partial>; interface _Impl { /** @@ -440,10 +495,12 @@ declare namespace SemanticUI { } } - interface MetadataSettings extends Pick { } + type MetadataSettings = MetadataSettings.Param; namespace MetadataSettings { - type Param = MetadataSettings | object; + type Param = (Pick<_Impl, 'cache'> | + Pick<_Impl, 'results'>) & + Partial>; interface _Impl { /** @@ -457,10 +514,15 @@ declare namespace SemanticUI { } } - interface ClassNameSettings extends Pick { } + type ClassNameSettings = ClassNameSettings.Param; namespace ClassNameSettings { - type Param = ClassNameSettings | object; + type Param = (Pick<_Impl, 'active'> | + Pick<_Impl, 'empty'> | + Pick<_Impl, 'focus'> | + Pick<_Impl, 'loading'> | + Pick<_Impl, 'pressed'>) & + Partial>; interface _Impl { /** @@ -486,10 +548,17 @@ declare namespace SemanticUI { } } - interface ErrorSettings extends Pick { } + type ErrorSettings = ErrorSettings.Param; namespace ErrorSettings { - type Param = ErrorSettings | object; + type Param = (Pick<_Impl, 'source'> | + Pick<_Impl, 'noResults'> | + Pick<_Impl, 'logging'> | + Pick<_Impl, 'noTemplate'> | + Pick<_Impl, 'serverError'> | + Pick<_Impl, 'maxResults'> | + Pick<_Impl, 'method'>) & + Partial>; interface _Impl { /** diff --git a/types/semantic-ui-search/semantic-ui-search-tests.ts b/types/semantic-ui-search/semantic-ui-search-tests.ts index 86760f2832..25d964a5db 100644 --- a/types/semantic-ui-search/semantic-ui-search-tests.ts +++ b/types/semantic-ui-search/semantic-ui-search-tests.ts @@ -1,5 +1,5 @@ function test_search_static() { - $.fn.search.settings.error.method = 'method'; + $.fn.search.settings.error!.method = 'method'; $.fn.search.settings.namespace = 'namespace'; $.fn.search.settings.name = 'name'; $.fn.search.settings.silent = false; @@ -10,31 +10,32 @@ function test_search_static() { function test_search() { const selector = '.ui.search'; - $(selector).search('query', () => { }) === $(); - $(selector).search('display message', 'text', 'type') === $(); - $(selector).search('cancel query') === $(); - $(selector).search('search local', 'query') === $(); - $(selector).search('has minimum characters') === true; - $(selector).search('search remote', 'query', () => { }) === $(); - $(selector).search('search object', 'query', {}, ['searchField']) === {}; - $(selector).search('cancel query') === $(); - $(selector).search('is focused') === false; - $(selector).search('is visible') === true; - $(selector).search('is empty') === false; - $(selector).search('get value') === {}; - $(selector).search('get result', 'value') === {}; - $(selector).search('set value', 'value') === $(); - $(selector).search('read cache', 'query') === $(); - $(selector).search('clear cache', 'query') === $(); - $(selector).search('write cache', 'query') === $(); - $(selector).search('add results', 'html') === $(); - $(selector).search('show results', () => { }) === $(); - $(selector).search('hide results', () => { }) === $(); - $(selector).search('generate results', {}) === $(); - $(selector).search('destroy') === $(); - $(selector).search('setting', 'debug', undefined) === false; - $(selector).search('setting', 'debug') === false; - $(selector).search('setting', 'debug', true) === $(); + $(selector).search('query', () => { }); // $ExpectType JQuery + $(selector).search('display message', 'text', 'type'); // $ExpectType JQuery + $(selector).search('cancel query'); // $ExpectType JQuery + $(selector).search('search local', 'query'); // $ExpectType JQuery + $(selector).search('has minimum characters'); // $ExpectType boolean + $(selector).search('search remote', 'query', () => { }); // $ExpectType JQuery + $(selector).search('search object', 'query', {}, ['searchField']); // $ExpectType any + $(selector).search('cancel query'); // $ExpectType JQuery + $(selector).search('is focused'); // $ExpectType boolean + $(selector).search('is visible'); // $ExpectType boolean + $(selector).search('is empty'); // $ExpectType boolean + $(selector).search('get value'); // $ExpectType any + $(selector).search('get result', 'value'); // $ExpectType any + $(selector).search('set value', 'value'); // $ExpectType JQuery + $(selector).search('read cache', 'query'); // $ExpectType JQuery + $(selector).search('clear cache', 'query'); // $ExpectType JQuery + $(selector).search('write cache', 'query'); // $ExpectType JQuery + $(selector).search('add results', 'html'); // $ExpectType JQuery + $(selector).search('show results', () => { }); // $ExpectType JQuery + $(selector).search('hide results', () => { }); // $ExpectType JQuery + $(selector).search('generate results', {}); // $ExpectType JQuery + $(selector).search('destroy'); // $ExpectType JQuery + $(selector).search('setting', 'debug', undefined); // $ExpectType boolean + $(selector).search('setting', 'debug'); // $ExpectType boolean + $(selector).search('setting', 'debug', true); // $ExpectType JQuery + // $ExpectType JQuery $(selector).search('setting', { namespace: 'namespace', name: 'name', @@ -42,7 +43,8 @@ function test_search() { debug: true, performance: true, verbose: true - }) === $(); + }); + // $ExpectType JQuery $(selector).search({ apiSettings: { on: 'on', @@ -62,56 +64,58 @@ function test_search() { urlData: false, response: false, responseAsync(settings, callback) { - settings === ({} as SemanticUI.ApiSettings); - callback === ((response: any) => { }); + settings; // $ExpectType Param + callback; // $ExpectType (response: any) => void }, mockResponse: false, mockResponseAsync(settings, callback) { - settings === ({} as SemanticUI.ApiSettings); - callback === ((response: any) => { }); + settings; // $ExpectType Param + callback; // $ExpectType (response: any) => void }, method: 'post', dataType: 'xml', data: {}, beforeSend(settings) { - settings === ({} as SemanticUI.ApiSettings); + settings; // $ExpectType Param }, beforeXHR(xhrObject) { - xhrObject === ({} as JQueryXHR); + xhrObject; // $ExpectType jqXHR }, onRequest(promise, xhr) { - promise === ({} as JQueryDeferred); - xhr === ({} as JQueryXHR); + promise; // $ExpectType Deferred + xhr; // $ExpectType jqXHR }, onResponse(response) { - response === ({} as any); + response; // $ExpectType any }, successTest(response) { - return response === ({} as any); + response; // $ExpectType any + + return false; }, onSuccess(response, element, xhr) { - response === ({} as any); - element === $(); - xhr === ({} as JQueryXHR); + response; // $ExpectType any + element; // $ExpectType JQuery + xhr; // $ExpectType jqXHR }, onComplete(response, element, xhr) { - response === ({} as any); - element === $(); - xhr === ({} as JQueryXHR); + response; // $ExpectType any + element; // $ExpectType JQuery + xhr; // $ExpectType jqXHR }, onFailure(response, element) { - response === ({} as any); - element === $(); + response; // $ExpectType any + element; // $ExpectType JQuery }, onError(errorMessage, element, xhr) { - errorMessage === ''; - element === $(); - xhr === ({} as JQueryXHR); + errorMessage; // $ExpectType string + element; // $ExpectType JQuery + xhr; // $ExpectType jqXHR }, onAbort(errorMessage, element, xhr) { - errorMessage === ''; - element === $(); - xhr === ({} as JQueryXHR); + errorMessage; // $ExpectType string + element; // $ExpectType JQuery + xhr; // $ExpectType jqXHR }, regExp: { required: /{\$*[A-z0-9]+}/g, @@ -175,41 +179,52 @@ function test_search() { searchDelay: 10, easing: 'easeOutExpo', onSelect(result, response) { - this === $(); - result === {}; - response === {}; + this; // $ExpectType JQuery + result; // $ExpectType any + response; // $ExpectType any + return false; }, onResultsAdd(html) { - this === $(); - html === 'html'; + this; // $ExpectType JQuery + html; // $ExpectType string + return false; }, onSearchQuery(query) { - this === $(); - query === 'query'; + this; // $ExpectType JQuery + query; // $ExpectType string }, onResults(response) { - this === $(); - response === {}; + this; // $ExpectType JQuery + response; // $ExpectType any }, onResultsOpen() { - this === $(); + this; // $ExpectType JQuery }, onResultsClose() { - this === $(); + this; // $ExpectType JQuery }, templates: { escape(string) { - return string; + string; // $ExpectType string + + return 'escape'; }, message(message, type) { - return message + type; + message; // $ExpectType string + type; // $ExpectType string + + return 'message'; }, category(response) { + response; // $ExpectType any + return 'category'; }, standard(response) { + response; // $ExpectType any + return 'standard'; } }, @@ -244,12 +259,16 @@ function test_search() { maxResults: 'maxResults', method: 'method' } - }) === $(); - $(selector).search() === $(); + }); + $(selector).search(); // $ExpectType JQuery + + $(selector).search('foo'); // $ExpectError + $(selector).search({ foo: 'bar' }); // $ExpectError } import search = require('semantic-ui-search'); function test_module() { + search; // $ExpectType Search $.fn.search = search; }