mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
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:
committed by
Sheetal Nandi
parent
d428e7ef97
commit
eb5efcaf99
Vendored
+6
@@ -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
@@ -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} />);
|
||||
|
||||
Reference in New Issue
Block a user