diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..d21917b --- /dev/null +++ b/index.d.ts @@ -0,0 +1,37 @@ +// Type definitions ported from DefinitelyTyped +// Ported by: M4rk9696 +// Original Definitions by: Ɓukasz Ostrowski + +import { Chalk } from 'chalk'; +import type {SpinnerName} from 'cli-spinners'; +import type { Component } from 'react'; + +type StringifyPartial = { + [P in keyof T]?: string; +}; + +type BooleansPartial = { + [P in keyof T]?: boolean; +}; + +type TupleOfNumbersPartial = { + [P in keyof T]?: [number, number, number]; +}; +// Omit taken from https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html +type Omit = Pick>; + +type ChalkColorModels = Pick; +type ChalkKeywordsAndHexes = Pick; +type ChalkCommons = Omit; + +interface SpinnerProps { + type?: SpinnerName; +} + +type ChalkProps = BooleansPartial + & StringifyPartial + & TupleOfNumbersPartial; + +declare class Spinner extends Component { } + +export = Spinner; diff --git a/index.test-d.tsx b/index.test-d.tsx new file mode 100644 index 0000000..a7f69d9 --- /dev/null +++ b/index.test-d.tsx @@ -0,0 +1,12 @@ +import * as React from "react"; +import Spinner = require("."); +import { render } from "ink"; + +render( + <> + + + + + +); diff --git a/package.json b/package.json index b1e0a08..3b00516 100644 --- a/package.json +++ b/package.json @@ -10,17 +10,19 @@ "url": "github.com/vadimdemedes" }, "main": "build/index.js", + "types": "index.d.ts", "engines": { "node": ">=8" }, "scripts": { "pretest": "npm run build", - "test": "xo && ava", + "test": "tsc --noEmit --jsx react --module commonjs index.test-d.tsx && xo && ava", "build": "babel src --out-dir=build", "prepare": "npm run build" }, "files": [ - "build" + "build", + "index.d.ts" ], "keywords": [ "ink", @@ -44,7 +46,7 @@ "@babel/preset-react": "^7.0.0", "@babel/register": "^7.10.3", "ava": "^3.9.0", - "babel-eslint": "^10.0.1", + "babel-eslint": "^10.1.0", "delay": "^4.1.0", "eslint-config-xo-react": "^0.23.0", "eslint-plugin-react": "^7.20.0", @@ -52,6 +54,7 @@ "ink": "^2.0.0", "ink-testing-library": "^1.0.0", "react": "^16.8.2", + "typescript": "^3.9.5", "xo": "^0.32.0" }, "peerDependencies": { @@ -76,6 +79,10 @@ "parser": "babel-eslint", "extends": [ "xo-react" + ], + "ignores": [ + "index.d.ts", + "index.test-d.tsx" ] } } diff --git a/test.js b/test.js index ed087f4..823be42 100644 --- a/test.js +++ b/test.js @@ -14,5 +14,9 @@ test('render spinner', async t => { const uniqueFrames = [...new Set(frames)]; + if (process.env.CI && uniqueFrames[uniqueFrames.length - 1] === '\n') { + uniqueFrames.pop(); + } + t.deepEqual(uniqueFrames, spinner.frames); });