Skip to content
This repository was archived by the owner on Sep 21, 2019. It is now read-only.

Default state to {} #5

Merged
merged 1 commit into from
Jul 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function isReactComponent(classDeclaration: ts.ClassDeclaration, typeChec
/**
* Determine if a ts.HeritageClause is React HeritageClause
*
* @example `extends React.Component<{}, void>` is a React HeritageClause
* @example `extends React.Component<{}, {}>` is a React HeritageClause
*
* @todo: this is lazy. Use the typeChecker instead
* @param clause
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/react-js-make-props-and-state-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function reactJSMakePropsAndStateInterfaceTransformFactoryFactory(typeChe
const initialStateIsVoid = initialState.kind === ts.SyntaxKind.VoidKeyword;
const collectedStateTypes = getStateLookingForSetStateCalls(classDeclaration, typeChecker);
if (!collectedStateTypes.length && initialStateIsVoid) {
return initialState;
return ts.createTypeLiteralNode([]);
}
if (!initialStateIsVoid) {
collectedStateTypes.push(initialState)
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/basic/output.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

type MyComponentProps = {};
type MyComponentState = void;
type MyComponentState = {};

export default class MyComponent extends React.Component<MyComponentProps, MyComponentState> {
render() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

export default class MyComponent extends React.Component<{}, void> {
export default class MyComponent extends React.Component<{}, {}> {
render() {
return <div />;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

type MyComponentProps = {};
type MyComponentState = void;
type MyComponentState = {};
export default class MyComponent extends React.Component<MyComponentProps, MyComponentState> {
render() {
return <div />;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

export default class MyComponent extends React.Component<{}, void> {
export default class MyComponent extends React.Component<{}, {}> {
render() {
return <div />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';

export default class MyComponent extends React.Component<{
foo: string;
}, void> {
}, {}> {
static get propTypes() {
return {
foo: React.PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class MyComponent extends React.Component<{
stringRequired: string;
nodeRequired: number | string | JSX.Element;
elementRequired: JSX.Element;
}, void> {
}, {}> {
static propTypes = {
any: React.PropTypes.any,
array: React.PropTypes.array,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';

export default class MyComponent extends React.Component<{
foo: string;
}, void> {
}, {}> {
static propTypes = {
foo: React.PropTypes.string.isRequired,
};
Expand Down