Fixing typings (again 🤷🏼‍♂️) + test for them (#682)

* add index notation

* add types check
This commit is contained in:
Konstantin Vyatkin 2019-10-24 07:02:34 -04:00 committed by Josh Johnson
parent 1dbab0f29e
commit a35c8b9009
2 changed files with 41 additions and 9 deletions

27
.github/workflows/types.yml vendored Normal file
View file

@ -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

23
types/index.d.ts vendored
View file

@ -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 <https://github.com/arthurvasconcelos>, Josh Johnson <https://github.com/jshjohnson>, Zack Schuster <https://github.com/zackschuster>
// 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<sting, any>;
customProperties?: Record<string, any>;
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<Choice>;
/**
* Function to run once Choices initialises.
@ -724,14 +723,20 @@ export default class Choices {
wasTap: boolean;
constructor(
element:
| string
| HTMLInputElement
| HTMLSelectElement
| Array<string | HTMLInputElement | HTMLSelectElement>,
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.
*