diff --git a/types/select2/v3/index.d.ts b/types/select2/v3/index.d.ts index 3c8fc11155..f4a0c01efb 100644 --- a/types/select2/v3/index.d.ts +++ b/types/select2/v3/index.d.ts @@ -4,7 +4,6 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 - /// interface Select2QueryOptions { @@ -23,8 +22,8 @@ interface AjaxFunction { interface Select2AjaxOptions extends JQueryAjaxSettings { transport?: AjaxFunction; /** - * Url to make request to, Can be string or a function returning a string. - */ + * Url to make request to, Can be string or a function returning a string. + */ url?: any; dataType?: string; quietMillis?: number; @@ -93,77 +92,77 @@ interface Select2Plugin { (): JQuery; (it: IdTextPair): JQuery; - /** - * Get the id value of the current selection - */ + /** + * Get the id value of the current selection + */ (method: 'val'): any; - /** - * Set the id value of the current selection - * @params value Value to set the id to - * @params triggerChange Should a change event be triggered - */ + /** + * Set the id value of the current selection + * @params value Value to set the id to + * @params triggerChange Should a change event be triggered + */ (method: 'val', value: any, triggerChange?: boolean): any; - /** - * Get the data object of the current selection - */ + /** + * Get the data object of the current selection + */ (method: 'data'): any; - /** - * Set the data of the current selection - * @params value Object to set the data to - * @params triggerChange Should a change event be triggered - */ + /** + * Set the data of the current selection + * @params value Object to set the data to + * @params triggerChange Should a change event be triggered + */ (method: 'data', value: any, triggerChange?: boolean): any; - /** - * Whether it is open - */ + /** + * Whether it is open + */ (method: 'opened'): boolean; - /** - * Whether it is in focus - */ + /** + * Whether it is in focus + */ (method: 'isFocused'): boolean; - /** - * Reverts changes to DOM done by Select2. Any selection done via Select2 will be preserved. - */ + /** + * Reverts changes to DOM done by Select2. Any selection done via Select2 will be preserved. + */ (method: 'destroy'): JQuery; - /** - * Opens the dropdown - */ + /** + * Opens the dropdown + */ (method: 'open'): JQuery; - /** - * Closes the dropdown - */ + /** + * Closes the dropdown + */ (method: 'close'): JQuery; - /** - * Disables Select2 - */ + /** + * Disables Select2 + */ (method: 'disable'): JQuery; - /** - * Enables or disables Select2 and its underlying form component - * @param value True if it should be enabled false if it should be disabled - */ + /** + * Enables or disables Select2 and its underlying form component + * @param value True if it should be enabled false if it should be disabled + */ (method: 'enable', value?: boolean): JQuery; - /** - * Enable its focus - */ + /** + * Enable its focus + */ (method: 'focus'): JQuery; - /** - * Toggles readonly mode on Select2 and its underlying form component - * @param value True if it should be readonly false if it should be read write - */ + /** + * Toggles readonly mode on Select2 and its underlying form component + * @param value True if it should be readonly false if it should be read write + */ (method: 'readonly', value: boolean): JQuery; - /** - * Retrieves the main container element that wraps all of DOM added by Select2 - */ + /** + * Retrieves the main container element that wraps all of DOM added by Select2 + */ (method: 'container'): JQuery; - /** - * Notifies Select2 that a drag and drop sorting operation has started - */ + /** + * Notifies Select2 that a drag and drop sorting operation has started + */ (method: 'onSortStart'): JQuery; - /** - * Notifies Select2 that a drag and drop sorting operation has finished - */ + /** + * Notifies Select2 that a drag and drop sorting operation has finished + */ (method: 'onSortEnd'): JQuery; - /** + /** * Executes a new search using the provided value. Example: $("#tags").select2("search", "California") */ (method: 'search'): JQuery; diff --git a/types/select2/v3/select2-tests.ts b/types/select2/v3/select2-tests.ts index fe7f900e3d..4a0a496e13 100644 --- a/types/select2/v3/select2-tests.ts +++ b/types/select2/v3/select2-tests.ts @@ -9,9 +9,9 @@ $("#e2_2").select2({ $("#e3").select2({ minimumInputLength: 2 }); -function format(state) { +function format(state: any) { if (!state.id) return state.text; - return "" + state.text; + return `${state.text}`; } $("#e4").select2({ formatResult: format, @@ -21,10 +21,10 @@ $("#e5").select2({ minimumInputLength: 1, query: function (query) { console.info('current element value:', query.element.val()); - var data = { results: [] }, i, j, s; - for (i = 1; i < 5; i++) { - s = ""; - for (j = 0; j < i; j++) { s = s + query.term; } + const data = { results: [] as IdTextPair[] }; + for (let i = 1; i < 5; i++) { + let s = ""; + for (let j = 0; j < i; j++) { s = s + query.term; } data.results.push({ id: query.term + i, text: s }); } } @@ -35,7 +35,7 @@ $("#e10").select2({ data: [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }, { id: 3, text: 'invalid' }, { id: 4, text: 'wontfix' }] }); -var data = [{ id: 0, tag: 'enhancement' }, { id: 1, tag: 'bug' }, { id: 2, tag: 'duplicate' }, { id: 3, tag: 'invalid' }, { id: 4, tag: 'wontfix' }]; +const data = [{ id: 0, tag: 'enhancement' }, { id: 1, tag: 'bug' }, { id: 2, tag: 'duplicate' }, { id: 3, tag: 'invalid' }, { id: 4, tag: 'wontfix' }]; $("#e10_2").select2({ data: { results: data, text: 'tag' }, @@ -44,11 +44,20 @@ $("#e10_2").select2({ }); $("#e10_3").select2({ - data: { results: data, text: function (item) { console.log('called with', item); return item.tag; } }, + data: { + results: data, + text: (item: {tag: string}) => { + console.log('called with', item); + return item.tag; + } + }, formatSelection: format, formatResult: format }); -var movieFormatResult, movieFormatSelection; + +let movieFormatResult; +let movieFormatSelection; + $("#e6").select2({ placeholder: "Search for a movie", minimumInputLength: 1, @@ -75,7 +84,7 @@ $("#e6").select2({ placeholder: "Search for a movie", minimumInputLength: 1, ajax: { - url: () => { return "http://api.rottentomatoes.com/api/public/v1.0/movies.json"; }, + url: () => "http://api.rottentomatoes.com/api/public/v1.0/movies.json", dataType: 'jsonp', data: function (term, page) { return { @@ -131,7 +140,7 @@ $("#e7").select2({ }; }, results: function (data, page) { - var more = (page * 10) < data.total; + const more = (page * 10) < data.total; return { results: data.movies, more: more }; } }, @@ -140,7 +149,7 @@ $("#e7").select2({ dropdownCssClass: "bigdrop" }); -function sort(elements) { +function sort(elements: any) { return elements.sort(); } @@ -170,13 +179,12 @@ $("#e11_2").select2({ multiple: true, data: [{ id: 0, text: 'story' }, { id: 1, text: 'bug' }, { id: 2, text: 'task' }] }); -function log(e) { - var item = $("
  • " + e + "
  • "); +function log(e: string) { + const item = $(`
  • ${e}
  • `); $("#events_11").append(item); item.animate({ opacity: 1 }, 10000, 'linear', function () { item.animate({ opacity: 0 }, 2000, 'linear', function () { item.remove(); }); }); } $("#e11") - // TS 0.9.5: correct overload not resolved https://typescript.codeplex.com/discussions/472172 .on("change", function (e: Select2JQueryEventObject) { log(JSON.stringify({ val: e.val, added: e.added, removed: e.removed })); }) .on("open", function () { log("open"); }); $("#e11_2") @@ -201,7 +209,7 @@ $("#e16_2").select2(); $("#e16_enable").click(function () { $("#e16,#e16_2").select2("enable"); }); $("#e16_disable").click(function () { $("#e16,#e16_2").select2("enable", false); }); $("#e17").select2({ - matcher: function (term, text) { return text.toUpperCase().indexOf(term.toUpperCase()) == 0; } + matcher: function (term, text) { return text.toUpperCase().indexOf(term.toUpperCase()) === 0; } }); $("#e17_2").select2({ matcher: function (term, text, opt) { @@ -210,22 +218,26 @@ $("#e17_2").select2({ } }); $("#e18,#e18_2").select2(); -alert("Selected value is: " + $("#e8").select2("val")); $("#e8").select2("val", { id: "CA", text: "Califoria" }); -$("#e19").select2({nextSearchTerm: function(selectedObject: object, currentSearchTerm: string) { - return currentSearchTerm; -}}); +alert("Selected value is: " + $("#e8").select2("val")); +$("#e8").select2("val", {id: "CA", text: "Califoria"}); -$('#e20').select2({ - tokenizer: (textInput, selection, selectCallback, options) => { - if (options.dropdownAutoWidth) { - selectCallback(); - return null; - } else if (options.allowClear) { - selectCallback(textInput + '_'); - return textInput + '_'; +$("#e1").select2({ + nextSearchTerm: (selectedObject: object, currentSearchTerm: string) => { + return currentSearchTerm; + } +}); + +$("#id").select2({ + tokenizer: (textInput, selection, selectCallback, options) => { + if (options.dropdownAutoWidth) { + selectCallback(); + return null; + } else if (options.allowClear) { + selectCallback(textInput + '_'); + return textInput + '_'; + } + selection.push('extra'); } - selection.push('extra'); - } }); $("#e8").select2("val"); diff --git a/types/select2/v3/tsconfig.json b/types/select2/v3/tsconfig.json index 8b8f30ed05..aeb9f31a86 100644 --- a/types/select2/v3/tsconfig.json +++ b/types/select2/v3/tsconfig.json @@ -5,8 +5,8 @@ "es6", "dom" ], - "noImplicitAny": false, - "noImplicitThis": false, + "noImplicitAny": true, + "noImplicitThis": true, "strictNullChecks": false, "strictFunctionTypes": true, "baseUrl": "../../", diff --git a/types/select2/v3/tslint.json b/types/select2/v3/tslint.json index a41bf5d19a..fdbd83d321 100644 --- a/types/select2/v3/tslint.json +++ b/types/select2/v3/tslint.json @@ -1,79 +1,9 @@ { "extends": "dtslint/dt.json", "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false + "unified-signatures": false } }