Add missing typings for Component constructor (#37897)

* add tests for missing constructor and Indent types

* add missing typings

* Improve props typings

* Add missing prop
This commit is contained in:
James Adarich
2019-08-26 08:12:11 -07:00
committed by Sheetal Nandi
parent d428e7ef97
commit eb5efcaf99
2 changed files with 18 additions and 6 deletions
+6
View File
@@ -1,6 +1,7 @@
// Type definitions for ink 0.5
// Project: https://github.com/vadimdemedes/ink#readme
// Definitions by: Carlos Precioso <https://github.com/cprecioso>
// James Adarich <https://github.com/jamesadarich>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@@ -61,6 +62,9 @@ export abstract class Component<
> {
readonly props: P & { children?: InkNode };
readonly context: C;
state: S;
constructor(props?: P);
setState(
nextState:
@@ -122,6 +126,8 @@ export namespace h {
}
export const Fragment: typeof h.Fragment;
export const Indent: ComponentClass;
export const Color: ComponentClass<{
rgb?: [number, number, number];
hsl?: [number, number, number];
+12 -6
View File
@@ -1,19 +1,25 @@
// @jsx h
import { Color, Component, Fragment, render } from "ink";
import { Color, Component, Fragment, Indent, render } from "ink";
class Counter extends Component<{}, { i: number }> {
interface CounterProps {
totalTests: number;
}
class Counter extends Component<CounterProps, { i: number }> {
timer = null as ReturnType<typeof setInterval> | null;
state = { i: 0 };
constructor() {
super();
constructor(props: CounterProps) {
super(props);
}
render() {
return (
<Fragment>
<Color green>{this.state.i} tests passed</Color>
<Indent>
<Color green>{this.state.i} / {this.props.totalTests} tests passed</Color>
</Indent>
</Fragment>
);
}
@@ -31,4 +37,4 @@ class Counter extends Component<{}, { i: number }> {
}
}
render(<Counter />);
render(<Counter totalTests={100} />);