From 061219cb0035f24a34e2541da142f42d54c8bd95 Mon Sep 17 00:00:00 2001 From: Dieter Luypaert Date: Wed, 3 Jul 2019 11:43:57 +0200 Subject: [PATCH] Add type info for choice, group, and item (#609) Refs: 551 --- .eslintignore | 1 + types/index.d.ts | 47 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/.eslintignore b/.eslintignore index c2658d7..81acc7f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ node_modules/ +types/ diff --git a/types/index.d.ts b/types/index.d.ts index 626fa9d..1e23ab0 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,8 +1,8 @@ -// Type definitions for Choices.js 3.0.2 +// Type definitions for Choices.js 7.0.0 // Project: https://github.com/jshjohnson/Choices // Definitions by: Arthur vasconcelos , Josh Johnson , Zack Schuster // Definitions: https://github.com/jshjohnson/Choices -// TypeScript Version: 2.6.2 +// TypeScript Version: 2.9.2 // Choices Namespace declare namespace Choices { @@ -16,6 +16,19 @@ declare namespace Choices { type callbackOnCreateTemplates = (template: strToEl) => Choices.Templates; } + interface Choice { + customProperties?: { [prop: string]: any }; + disabled?: boolean; + elementId?: string; + groupId?: string; + id?: string; + keyCode?: number; + label: string; + placeholder?: any; + selected?: boolean; + value: any; + } + /** * Events fired by Choices behave the same as standard events. Each event is triggered on the element passed to Choices (accessible via `this.passedElement`. Arguments are accessible within the `event.detail` object. */ @@ -111,6 +124,24 @@ declare namespace Choices { "hideDropdown": CustomEvent; } + interface Group { + active?: boolean; + disabled?: boolean; + id?: string; + value: any; + } + + interface Item { + choiceId?: string; + customProperties?: { [prop: string]: any }; + groupId?: string; + id?: string; + keyCode?: number; + label: string; + placeholder?: string; + value: any; + } + interface Templates { containerOuter?: (direction: string) => HTMLElement; containerInner?: () => HTMLElement; @@ -682,8 +713,8 @@ export default class Choices { canSearch: boolean; placeholder: boolean; - presetChoices: any[]; - presetItems: any[]; + presetChoices: Choices.Choice[]; + presetItems: Choices.Item[]; readonly baseId: string; @@ -849,7 +880,7 @@ export default class Choices { setChoiceByValue(value: string | string[]): this; /** Direct populate choices */ - setChoices(choices: any[], value: string, label: string, replaceChoices?: boolean): this; + setChoices(choices: Choices.Choice[], value: string, label: string, replaceChoices?: boolean): this; /** * Removes all items, choices and groups. Use with caution. @@ -904,13 +935,13 @@ export default class Choices { ajax(fn: (values: any) => any): this; /** Render group choices into a DOM fragment and append to choice list */ - private createGroupsFragment(groups: any[], choices: any[], fragment: DocumentFragment): DocumentFragment; + private createGroupsFragment(groups: Choices.Group[], choices: Choices.Choice[], fragment: DocumentFragment): DocumentFragment; /** Render choices into a DOM fragment and append to choice list */ - private createChoicesFragment(choices: any[], fragment: DocumentFragment, withinGroup?: boolean): DocumentFragment; + private createChoicesFragment(choices: Choices.Choice[], fragment: DocumentFragment, withinGroup?: boolean): DocumentFragment; /** Render items into a DOM fragment and append to items list */ - private _createItemsFragment(items: any[], fragment?: DocumentFragment): void; + private _createItemsFragment(items: Choices.Item[], fragment?: DocumentFragment): void; /** Render DOM with values */ private render(): void;