Definitions for ink-spinner

This commit is contained in:
lukostry
2019-02-20 00:54:30 +01:00
parent d77c47c753
commit ad77aaa3be
4 changed files with 75 additions and 0 deletions

39
types/ink-spinner/index.d.ts vendored Normal file
View File

@@ -0,0 +1,39 @@
// Type definitions for ink-spinner 2.0
// Project: https://github.com/vadimdemedes/ink-spinner#readme
// Definitions by: Łukasz Ostrowski <https://github.com/lukostry>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { Chalk } from 'chalk';
import * as cliSpinners from 'cli-spinners';
import { Component } from 'ink';
type StringifyPartial<T> = {
[P in keyof T]?: string;
};
type BooleansPartial<T> = {
[P in keyof T]?: boolean;
};
type TupleOfNumbersPartial<T> = {
[P in keyof T]?: [number, number, number];
};
// Omit taken from https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
type ChalkColorModels = Pick<Chalk, 'rgb' | 'hsl' | 'hsv' | 'hwb' | 'bgRgb' | 'bgHsl' | 'bgHsv' | 'bgHwb'>;
type ChalkKeywordsAndHexes = Pick<Chalk, 'keyword' | 'hex' | 'bgKeyword' | 'bgHex'>;
type ChalkCommons = Omit<Chalk, keyof ChalkColorModels | keyof ChalkKeywordsAndHexes | 'constructor' | 'level' | 'enabled'>;
interface SpinnerProps {
type?: cliSpinners.SpinnerName;
}
type ChalkProps = BooleansPartial<ChalkCommons>
& StringifyPartial<ChalkKeywordsAndHexes>
& TupleOfNumbersPartial<ChalkColorModels>;
declare class Spinner extends Component<SpinnerProps & ChalkProps> { }
export = Spinner;

View File

@@ -0,0 +1,10 @@
/** @jsx h */
import { h } from 'ink';
import Spinner from 'ink-spinner';
// NOTE: `import Spinner = require('ink-spinner');` will work as well.
// If importing using ES6 default import as above,
// `allowSyntheticDefaultImports` flag in compiler options needs to be set to `true`
const Demo = () => {
return <Spinner type="line" rgb={[255, 255, 255]} />;
};

View File

@@ -0,0 +1,25 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"jsx": "react",
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ink-spinner-tests.tsx"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }