diff --git a/.github/workflows/types.yml b/.github/workflows/types.yml new file mode 100644 index 0000000..395834d --- /dev/null +++ b/.github/workflows/types.yml @@ -0,0 +1,27 @@ +name: TypeScript Check + +on: + pull_request: + paths: + - 'types/index.d.ts' + +jobs: + tsc: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + + - uses: actions/setup-node@v1 + with: + node-version: 12 + + - name: Install TypeScript + run: npm install -g typescript + + - name: Install required dependencies + run: npm i --only=production --no-optional --no-audit --ignore-scripts + + - name: Check typings file + run: tsc types/index.d.ts diff --git a/types/index.d.ts b/types/index.d.ts index 371a24a..4a257ec 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,8 +1,7 @@ -// Type definitions for Choices.js 7.0.0 +// Type definitions for Choices.js 7.1.x // Project: https://github.com/jshjohnson/Choices // Definitions by: Arthur vasconcelos , Josh Johnson , Zack Schuster // Definitions: https://github.com/jshjohnson/Choices -// TypeScript Version: 2.9.2 import { FuseOptions } from 'fuse.js'; @@ -21,7 +20,7 @@ declare namespace Choices { } interface Choice { - customProperties?: Record; + customProperties?: Record; disabled?: boolean; elementId?: string; groupId?: string; @@ -641,7 +640,7 @@ declare namespace Choices { /** * Choices uses the great Fuse library for searching. You can find more options here: https://github.com/krisk/Fuse#options */ - fuseOptions?: FuseOptions; + fuseOptions?: FuseOptions; /** * Function to run once Choices initialises. @@ -724,14 +723,20 @@ export default class Choices { wasTap: boolean; constructor( - element: - | string - | HTMLInputElement - | HTMLSelectElement - | Array, + selectorOrElement: string | HTMLInputElement | HTMLSelectElement, userConfig?: Choices.Options ); + /** + * It's impossible to declare in TypeScript what Choices constructor is actually doing: + * @see {@link https://github.com/Microsoft/TypeScript/issues/27594} + * it returns array of Choices in case if selectorOrElement is string + * and one instance of Choices otherwise + * This little hack will at least allow to use it in Typescript + * + */ + [index: number]: this; + /** * Creates a new instance of Choices, adds event listeners, creates templates and renders a Choices element to the DOM. *